diff --git a/src/backend/InvenTree/InvenTree/helpers_model.py b/src/backend/InvenTree/InvenTree/helpers_model.py index 925046aef1..fed539366a 100644 --- a/src/backend/InvenTree/InvenTree/helpers_model.py +++ b/src/backend/InvenTree/InvenTree/helpers_model.py @@ -281,6 +281,7 @@ def notify_responsible( instance, sender, content: NotificationBody = InvenTreeNotificationBodies.NewOrder, + html_context: Optional[dict] = None, exclude=None, extra_users: Optional[list] = None, ): @@ -293,6 +294,7 @@ def notify_responsible( instance: The newly created instance sender: Sender model reference content (NotificationBody, optional): _description_. Defaults to InvenTreeNotificationBodies.NewOrder. + html_context: Optional HTML context to include in the notification. Defaults to None. exclude (User, optional): User instance that should be excluded. Defaults to None. extra_users (list, optional): List of extra users to notify. Defaults to None. """ @@ -306,7 +308,14 @@ def notify_responsible( if extra_users: users.extend(extra_users) - notify_users(users, instance, sender, content=content, exclude=exclude) + notify_users( + users, + instance, + sender, + content=content, + html_context=html_context, + exclude=exclude, + ) def notify_users( @@ -314,6 +323,7 @@ def notify_users( instance, sender, content: NotificationBody = InvenTreeNotificationBodies.NewOrder, + html_context: Optional[dict] = None, exclude=None, ): """Notify all passed users or groups. @@ -326,6 +336,7 @@ def notify_users( instance: The newly created instance sender: Sender model reference content (NotificationBody, optional): _description_. Defaults to InvenTreeNotificationBodies.NewOrder. + html_context (dict, optional): Optional HTML context to include in the notification. Defaults to None. exclude (User, optional): User instance that should be excluded. Defaults to None. """ # Setup context for notification parsing @@ -345,9 +356,11 @@ def notify_users( 'template': {'subject': content.name.format(**content_context)}, } - tmp = content.template - if tmp: - context['template']['html'] = tmp.format(**content_context) + if tmp := content.template: + html_context = html_context or {} + html_context.update(content_context) + + context['template']['html'] = tmp.format(**html_context) # Create notification trigger_notification( diff --git a/src/backend/InvenTree/order/models.py b/src/backend/InvenTree/order/models.py index 6563bf1bc0..66a2aa31a5 100644 --- a/src/backend/InvenTree/order/models.py +++ b/src/backend/InvenTree/order/models.py @@ -1293,6 +1293,7 @@ class PurchaseOrder(TotalPriceMixin, Order): exclude=user, content=InvenTreeNotificationBodies.ItemsReceived, extra_users=line.part.part.get_subscribers(), + html_context={'order': self, 'stock_items': stock_items}, ) # Return a list of the created stock items diff --git a/src/backend/InvenTree/templates/email/purchase_order_received.html b/src/backend/InvenTree/templates/email/purchase_order_received.html index 46ff982e90..39deaab06e 100644 --- a/src/backend/InvenTree/templates/email/purchase_order_received.html +++ b/src/backend/InvenTree/templates/email/purchase_order_received.html @@ -9,3 +9,18 @@
{% trans "Click on the following link to view this order" %}: {{ link }}
{% endif %} {% endblock title %} + +{% block body %} +