Skip to content

Commit

Permalink
Add activity feed and update tasks accordingly for selected invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
sandeepsajan0 committed Feb 8, 2024
1 parent 0bef32f commit c369f43
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
12 changes: 12 additions & 0 deletions hypha/apply/activity/adapters/activity_feed.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from hypha.apply.activity.options import MESSAGES
from hypha.apply.projects.utils import (
get_invoice_public_status,
get_invoice_status_display_value,
get_project_public_status,
get_project_status_display_value,
)
Expand Down Expand Up @@ -66,6 +67,7 @@ class ActivityAdapter(AdapterBase):
MESSAGES.DISABLED_REPORTING: _("Reporting disabled"),
MESSAGES.BATCH_DELETE_SUBMISSION: "handle_batch_delete_submission",
MESSAGES.BATCH_ARCHIVE_SUBMISSION: "handle_batch_archive_submission",
MESSAGES.BATCH_UPDATE_INVOICE_STATUS: "handle_batch_update_invoice_status",
MESSAGES.ARCHIVE_SUBMISSION: _(
"{user} has archived the submission: {source.title}"
),
Expand Down Expand Up @@ -164,6 +166,16 @@ def handle_batch_archive_submission(self, sources, **kwargs):
title=submissions_text
)

def handle_batch_update_invoice_status(self, sources, invoices, **kwargs):
invoice_numbers = ", ".join([invoice.invoice_number for invoice in invoices])
invoice_status = invoices[0].status if invoices else ""
return _(
"Successfully updated status to {invoice_status} for invoices: {invoice_numbers}"
).format(
invoice_status=get_invoice_status_display_value(invoice_status),
invoice_numbers=invoice_numbers,
)

def handle_paf_assignment(self, source, paf_approvals, **kwargs):
if hasattr(paf_approvals, "__iter__"): # paf_approvals has to be iterable
users = ", ".join(
Expand Down
1 change: 1 addition & 0 deletions hypha/apply/activity/adapters/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
MESSAGES.CREATE_REMINDER: "reminder",
MESSAGES.DELETE_REMINDER: "reminder",
MESSAGES.REVIEW_REMINDER: "reminder",
MESSAGES.BATCH_UPDATE_INVOICE_STATUS: "invoices",
}


Expand Down
4 changes: 4 additions & 0 deletions hypha/apply/activity/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ class MESSAGES(TextChoices):
"BATCH_ARCHIVE_SUBMISSION",
_("batch archive submissions"),
)
BATCH_UPDATE_INVOICE_STATUS = (
"BATCH_INVOICE_STATUS_UPDATE",
_("batch update invoice status"),
)
STAFF_ACCOUNT_CREATED = "STAFF_ACCOUNT_CREATED", _("created new account")
STAFF_ACCOUNT_EDITED = "STAFF_ACCOUNT_EDITED", _("edited account")
ARCHIVE_SUBMISSION = "ARCHIVE_SUBMISSION", _("archived submission")
Expand Down
1 change: 0 additions & 1 deletion hypha/apply/projects/service_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,3 @@ def batch_update_invoices_status(invoices, user, status):
for invoice in invoices:
invoice.status = status
invoice.save(update_fields=["status"])
# notify about batch invoice status update
17 changes: 17 additions & 0 deletions hypha/apply/projects/views/payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,28 @@ class BatchUpdateInvoiceStatusView(DelegatedViewMixin, FormView):
def form_valid(self, form):
new_status = form.cleaned_data["invoice_action"]
invoices = form.cleaned_data["invoices"]
invoices_old_statuses = {invoice: invoice.status for invoice in invoices}
batch_update_invoices_status(
invoices=invoices,
user=self.request.user,
status=new_status,
)

# add activity feed for batch update invoice status
projects = Project.objects.filter(
id__in=[invoice.project.id for invoice in invoices]
)
messenger(
MESSAGES.BATCH_UPDATE_INVOICE_STATUS,
request=self.request,
user=self.request.user,
sources=projects,
related=invoices,
)

# update tasks for selected invoices
for invoice, old_status in invoices_old_statuses.items():
handle_tasks_on_invoice_update(old_status, invoice)
return super().form_valid(form)

def form_invalid(self, form):
Expand Down

0 comments on commit c369f43

Please sign in to comment.