Change target of PurchaseOrder notification (#4905)

* Change target of PurchaseOrder notification

- Triggered when order is placed
- No longer when order is created

* unit test fixes
This commit is contained in:
Oliver 2023-05-29 21:04:31 +10:00 committed by GitHub
parent 32331875fe
commit 3205527ebe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 13 deletions

View File

@ -484,6 +484,14 @@ class PurchaseOrder(TotalPriceMixin, Order):
trigger_event('purchaseorder.placed', id=self.pk)
# Notify users that the order has been placed
notify_responsible(
self,
PurchaseOrder,
exclude=self.created_by,
content=InvenTreeNotificationBodies.NewOrder
)
@transaction.atomic
def complete_order(self):
"""Marks the PurchaseOrder as COMPLETE.
@ -677,17 +685,6 @@ class PurchaseOrder(TotalPriceMixin, Order):
)
@receiver(post_save, sender=PurchaseOrder, dispatch_uid='purchase_order_post_save')
def after_save_purchase_order(sender, instance: PurchaseOrder, created: bool, **kwargs):
"""Callback function to be executed after a PurchaseOrder is saved."""
if not InvenTree.ready.canAppAccessDatabase(allow_test=True) or InvenTree.ready.isImportingData():
return
if created:
# Notify the responsible users that the purchase order has been created
notify_responsible(instance, sender, exclude=instance.created_by)
class SalesOrder(TotalPriceMixin, Order):
"""A SalesOrder represents a list of goods shipped outwards to a customer."""

View File

@ -367,18 +367,23 @@ class OrderTest(TestCase):
- The creating user should *not* receive a notification
"""
PurchaseOrder.objects.create(
po = PurchaseOrder.objects.create(
supplier=Company.objects.get(pk=1),
reference='XYZABC',
created_by=get_user_model().objects.get(pk=3),
responsible=Owner.create(obj=get_user_model().objects.get(pk=4)),
)
# Initially, no notifications
messages = common.models.NotificationMessage.objects.filter(
category='order.new_purchaseorder',
)
self.assertEqual(messages.count(), 1)
self.assertEqual(messages.count(), 0)
# Place the order
po.place_order()
# A notification should have been generated for user 4 (who is a member of group 3)
self.assertTrue(messages.filter(user__pk=4).exists())