2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-02 03:30:54 +00:00

Notification on new orders (#3145)

* Trigger a notification when a new SalesOrder is created

- Notify the "responsible" owners (excluding the creator)
- Add unit test for new notification

* Adds notification when a new PurchaseOrder is created

* Add notification when a new build order is created

- Includes unit tests

* Refactor order notification code

- Adds a "exclude users" option for sending notifications

* Fixes for notification refactoring

* make notification a helper

* reduce statements togehter

* make reuse easier

* Add docs

* Make context variables clearer

* fix assertation

* Fix set notation

Co-authored-by: Matthias <code@mjmair.com>
This commit is contained in:
Oliver
2022-06-07 08:11:11 +10:00
committed by GitHub
parent 00b75d792e
commit 6b038d85b6
8 changed files with 232 additions and 37 deletions

View File

@ -260,3 +260,27 @@ class SalesOrderTest(TestCase):
)
self.assertEqual(len(messages), 2)
def test_new_so_notification(self):
"""Test that a notification is sent when a new SalesOrder is created.
- The responsible user should receive a notification
- The creating user should *not* receive a notification
"""
SalesOrder.objects.create(
customer=self.customer,
reference='1234567',
created_by=get_user_model().objects.get(pk=3),
responsible=Owner.create(obj=Group.objects.get(pk=3))
)
messages = NotificationMessage.objects.filter(
category='order.new_salesorder',
)
# A notification should have been generated for user 4 (who is a member of group 3)
self.assertTrue(messages.filter(user__pk=4).exists())
# However *no* notification should have been generated for the creating user
self.assertFalse(messages.filter(user__pk=3).exists())