diff --git a/hypha/apply/activity/messaging.py b/hypha/apply/activity/messaging.py index fbf7eaa843ef59be59a5df9f231bb1c7cc652a4b..485f3f236cf7233ffaf489e4c7184a11e55f8fa2 100644 --- a/hypha/apply/activity/messaging.py +++ b/hypha/apply/activity/messaging.py @@ -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 [ { diff --git a/hypha/apply/projects/models/project.py b/hypha/apply/projects/models/project.py index 2a46509deda05bf5c8b3f0dca05a1bd3cf35b404..96461908df787c4f715fcb78e9b9a2b6846a1ccf 100644 --- a/hypha/apply/projects/models/project.py +++ b/hypha/apply/projects/models/project.py @@ -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 diff --git a/hypha/apply/users/forms.py b/hypha/apply/users/forms.py index 02d15e3e722d51655ef560bf122351622174004f..e31c91990db91822aa50eb1d8fd031973b5baca2 100644 --- a/hypha/apply/users/forms.py +++ b/hypha/apply/users/forms.py @@ -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(): diff --git a/hypha/apply/users/models.py b/hypha/apply/users/models.py index a559bd4fba7d6d3ffa65756a43e3455cf03f7a4f..4ed4890956e7e96e547d3ed61795551547c83293 100644 --- a/hypha/apply/users/models.py +++ b/hypha/apply/users/models.py @@ -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):