Skip to content
Snippets Groups Projects
Commit 2a0f33ba authored by Shrikrishna Singh's avatar Shrikrishna Singh
Browse files

Add slack notifications for the finance flow

parent d7da6200
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,18 @@ from django.db import models
from django.template.loader import render_to_string
from django.utils import timezone
from django.utils.translation import gettext as _
from hypha.apply.projects.models.payment import (
SUBMITTED,
RESUBMITTED,
CHANGES_REQUESTED_BY_STAFF,
CHANGES_REQUESTED_BY_FINANCE_1,
CHANGES_REQUESTED_BY_FINANCE_2,
APPROVED_BY_STAFF,
APPROVED_BY_FINANCE_1,
APPROVED_BY_FINANCE_2,
PAID,
DECLINED,
)
from .models import ALL, TEAM
from .options import MESSAGES
from .tasks import send_mail
......@@ -490,17 +501,36 @@ class SlackAdapter(AdapterBase):
]
recipients = [self.slack_id(source.lead)]
# Notify second reviewer when first reviewer is done.
if message_type == MESSAGES.NEW_REVIEW and related:
submission = source
if submission.assigned.with_roles().count() == 2 and related.author.reviewer == submission.assigned.with_roles().first().reviewer:
recipients.append(self.slack_id(submission.assigned.with_roles().last().reviewer))
if message_type == MESSAGES.UPDATE_INVOICE_STATUS:
if related.status in [SUBMITTED, RESUBMITTED, CHANGES_REQUESTED_BY_FINANCE_1, APPROVED_BY_FINANCE_2]:
# Notify project lead/staff
return recipients
if related.status in [APPROVED_BY_STAFF, CHANGES_REQUESTED_BY_FINANCE_2]:
# Notify finance 1
return [
self.slack_id(user)
for user in User.objects.finances_level_1()
if self.slack_id(user)
]
if related.status in [APPROVED_BY_FINANCE_1]:
# Notify finance 2
return [
self.slack_id(user)
for user in User.objects.finances_level_2()
if self.slack_id(user)
]
return []
return recipients
def batch_recipients(self, message_type, sources, **kwargs):
# We group the messages by lead
import ipdb; ipdb.set_trace()
leads = User.objects.filter(id__in=sources.values('lead'))
return [
{
......
......@@ -21,7 +21,6 @@ from wagtail.contrib.settings.models import BaseSetting, register_setting
from wagtail.core.fields import StreamField
from addressfield.fields import ADDRESS_FIELDS_ORDER
from hypha.apply.activity.messaging import MESSAGES, messenger
from hypha.apply.funds.models.mixins import AccessFormData
from hypha.apply.stream_forms.blocks import FormFieldsBlock
from hypha.apply.stream_forms.files import StreamFieldDataEncoder
......@@ -345,18 +344,18 @@ class Project(BaseStreamForm, AccessFormData, models.Model):
def has_deliverables(self):
return self.deliverables.exists()
def send_to_compliance(self, request):
"""Notify Compliance about this Project."""
# def send_to_compliance(self, request):
# """Notify Compliance about this Project."""
messenger(
MESSAGES.SENT_TO_COMPLIANCE,
request=request,
user=request.user,
source=self,
)
# messenger(
# MESSAGES.SENT_TO_COMPLIANCE,
# request=request,
# user=request.user,
# source=self,
# )
self.sent_to_compliance_at = timezone.now()
self.save(update_fields=['sent_to_compliance_at'])
# self.sent_to_compliance_at = timezone.now()
# self.save(update_fields=['sent_to_compliance_at'])
@register_setting
......
......@@ -49,7 +49,7 @@ class ProfileForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not self.instance.is_apply_staff:
if not self.instance.is_apply_staff_or_finance:
del self.fields['slack']
if not self.instance.has_usable_password():
......
......@@ -148,6 +148,10 @@ class User(AbstractUser):
@cached_property
def is_apply_staff(self):
return self.groups.filter(name=STAFF_GROUP_NAME).exists() or self.is_superuser
@cached_property
def is_apply_staff_or_finance(self):
return self.is_apply_staff or self.is_finance
@cached_property
def is_apply_staff_admin(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment