2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-05-06 07:18:48 +00:00

Notify users when a build order is completed (#3255)

This commit is contained in:
Oliver 2022-06-26 09:25:37 +10:00 committed by GitHub
parent 56bbda60b5
commit b2e31e3474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 3 deletions

View File

@ -32,6 +32,7 @@ import InvenTree.tasks
from plugin.events import trigger_event from plugin.events import trigger_event
import common.notifications
from part import models as PartModels from part import models as PartModels
from stock import models as StockModels from stock import models as StockModels
from users import models as UserModels from users import models as UserModels
@ -534,12 +535,51 @@ class Build(MPTTModel, ReferenceIndexingMixin):
self.subtract_allocated_stock(user) self.subtract_allocated_stock(user)
# Ensure that there are no longer any BuildItem objects # Ensure that there are no longer any BuildItem objects
# which point to thisFcan Build Order # which point to this Build Order
self.allocated_stock.all().delete() self.allocated_stock.all().delete()
# Register an event # Register an event
trigger_event('build.completed', id=self.pk) trigger_event('build.completed', id=self.pk)
# Notify users that this build has been completed
targets = [
self.issued_by,
self.responsible,
]
# Notify those users interested in the parent build
if self.parent:
targets.append(self.parent.issued_by)
targets.append(self.parent.responsible)
# Notify users if this build points to a sales order
if self.sales_order:
targets.append(self.sales_order.created_by)
targets.append(self.sales_order.responsible)
build = self
name = _(f'Build order {build} has been completed')
context = {
'build': build,
'name': name,
'slug': 'build.completed',
'message': _('A build order has been completed'),
'link': InvenTree.helpers.construct_absolute_url(self.get_absolute_url()),
'template': {
'html': 'email/build_order_completed.html',
'subject': name,
}
}
common.notifications.trigger_notification(
build,
'build.completed',
targets=targets,
context=context,
target_exclude=[user],
)
@transaction.atomic @transaction.atomic
def cancel_build(self, user, **kwargs): def cancel_build(self, user, **kwargs):
"""Mark the Build as CANCELLED. """Mark the Build as CANCELLED.

View File

@ -291,7 +291,7 @@ class InvenTreeNotificationBodies:
NewOrder = NotificationBody( NewOrder = NotificationBody(
name=_("New {verbose_name}"), name=_("New {verbose_name}"),
slug='{app_label}.new_{model_name}', slug='{app_label}.new_{model_name}',
message=_("A new {verbose_name} has been created and ,assigned to you"), message=_("A new order has been created and assigned to you"),
template='email/new_order_assigned.html', template='email/new_order_assigned.html',
) )
"""Send when a new order (build, sale or purchase) was created.""" """Send when a new order (build, sale or purchase) was created."""
@ -344,8 +344,10 @@ def trigger_notification(obj, category=None, obj_ref='pk', **kwargs):
if targets: if targets:
for target in targets: for target in targets:
if target is None:
continue
# User instance is provided # User instance is provided
if isinstance(target, get_user_model()): elif isinstance(target, get_user_model()):
if target not in target_exclude: if target not in target_exclude:
target_users.add(target) target_users.add(target)
# Group instance is provided # Group instance is provided

View File

@ -0,0 +1,27 @@
{% extends "email/email.html" %}
{% load i18n %}
{% load inventree_extras %}
{% block title %}
{{ message }}
{% if link %}
<p>{% trans "Click on the following link to view this order" %}: <a href="{{ link }}">{{ link }}</a></p>
{% endif %}
{% endblock title %}
{% block body %}
<tr style="height: 3rem; border-bottom: 1px solid">
<th>{% trans "Build Order" %}</th>
<th>{% trans "Part" %}</th>
<th>{% trans "Quantity" %}</th>
</tr>
<tr style="height: 3rem">
<td style="text-align: center;">{{ build }}</td>
<td style="text-align: center;">{{ build.part.full_name }}</td>
<td style="text-align: center;">{{ build.quantity }}</td>
</tr>
{% endblock body %}