mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 03:56:43 +00:00
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:
parent
32331875fe
commit
3205527ebe
@ -484,6 +484,14 @@ class PurchaseOrder(TotalPriceMixin, Order):
|
|||||||
|
|
||||||
trigger_event('purchaseorder.placed', id=self.pk)
|
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
|
@transaction.atomic
|
||||||
def complete_order(self):
|
def complete_order(self):
|
||||||
"""Marks the PurchaseOrder as COMPLETE.
|
"""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):
|
class SalesOrder(TotalPriceMixin, Order):
|
||||||
"""A SalesOrder represents a list of goods shipped outwards to a customer."""
|
"""A SalesOrder represents a list of goods shipped outwards to a customer."""
|
||||||
|
|
||||||
|
@ -367,18 +367,23 @@ class OrderTest(TestCase):
|
|||||||
- The creating user should *not* receive a notification
|
- The creating user should *not* receive a notification
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PurchaseOrder.objects.create(
|
po = PurchaseOrder.objects.create(
|
||||||
supplier=Company.objects.get(pk=1),
|
supplier=Company.objects.get(pk=1),
|
||||||
reference='XYZABC',
|
reference='XYZABC',
|
||||||
created_by=get_user_model().objects.get(pk=3),
|
created_by=get_user_model().objects.get(pk=3),
|
||||||
responsible=Owner.create(obj=get_user_model().objects.get(pk=4)),
|
responsible=Owner.create(obj=get_user_model().objects.get(pk=4)),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Initially, no notifications
|
||||||
|
|
||||||
messages = common.models.NotificationMessage.objects.filter(
|
messages = common.models.NotificationMessage.objects.filter(
|
||||||
category='order.new_purchaseorder',
|
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)
|
# A notification should have been generated for user 4 (who is a member of group 3)
|
||||||
self.assertTrue(messages.filter(user__pk=4).exists())
|
self.assertTrue(messages.filter(user__pk=4).exists())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user