mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-19 13:35:40 +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:
@ -9,7 +9,7 @@ from django.test import TestCase
|
||||
|
||||
import common.models
|
||||
import order.tasks
|
||||
from company.models import SupplierPart
|
||||
from company.models import Company, SupplierPart
|
||||
from InvenTree.status_codes import PurchaseOrderStatus
|
||||
from part.models import Part
|
||||
from stock.models import StockLocation
|
||||
@ -237,3 +237,29 @@ class OrderTest(TestCase):
|
||||
|
||||
self.assertEqual(msg.target_object_id, 1)
|
||||
self.assertEqual(msg.name, 'Overdue Purchase Order')
|
||||
|
||||
def test_new_po_notification(self):
|
||||
"""Test that a notification is sent when a new PurchaseOrder is created
|
||||
|
||||
- The responsible user(s) should receive a notification
|
||||
- The creating user should *not* receive a notification
|
||||
"""
|
||||
|
||||
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)),
|
||||
)
|
||||
|
||||
messages = common.models.NotificationMessage.objects.filter(
|
||||
category='order.new_purchaseorder',
|
||||
)
|
||||
|
||||
self.assertEqual(messages.count(), 1)
|
||||
|
||||
# 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())
|
||||
|
Reference in New Issue
Block a user