2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-07-01 19:20:55 +00:00

Merge pull request #2208 from rocheparadox/master

Email notification for low stock
This commit is contained in:
Oliver
2021-11-01 22:45:49 +11:00
committed by GitHub
6 changed files with 111 additions and 6 deletions

View File

@ -17,7 +17,7 @@ from django.db.models import Sum, Q
from django.db.models.functions import Coalesce
from django.core.validators import MinValueValidator
from django.contrib.auth.models import User
from django.db.models.signals import pre_delete
from django.db.models.signals import pre_delete, post_save, post_delete
from django.dispatch import receiver
from markdownx.models import MarkdownxField
@ -41,6 +41,7 @@ from users.models import Owner
from company import models as CompanyModels
from part import models as PartModels
from part import tasks as part_tasks
class StockLocation(InvenTreeTree):
@ -1651,6 +1652,24 @@ def before_delete_stock_item(sender, instance, using, **kwargs):
child.save()
@receiver(post_delete, sender=StockItem, dispatch_uid='stock_item_post_delete_log')
def after_delete_stock_item(sender, instance: StockItem, **kwargs):
"""
Function to be executed after a StockItem object is deleted
"""
part_tasks.notify_low_stock_if_required(instance.part)
@receiver(post_save, sender=StockItem, dispatch_uid='stock_item_post_save_log')
def after_save_stock_item(sender, instance: StockItem, **kwargs):
"""
Hook function to be executed after StockItem object is saved/updated
"""
part_tasks.notify_low_stock_if_required(instance.part)
class StockItemAttachment(InvenTreeAttachment):
"""
Model for storing file attachments against a StockItem object.

View File

@ -0,0 +1,30 @@
{% load i18n %}
<p>{% trans "Hi, " %} {{ part_name }} {% trans "is low on stock. Kindly do the needful." %}</p>
<table style="border-collapse:collapse; width: 80%;margin-left: 10%; font-size: 1rem">
<tr style="background: aliceblue; height: 4rem;">
<th colspan="3" style="padding-bottom: 1rem; font-size: 1.5rem; color:rgb(210,0, 0)">{% trans "Part low on stock" %}</th>
</tr>
<tr style="height: 3rem; border-bottom: 1px solid">
<th>{% trans "Part Name" %}</th>
<th>{% trans "Available Quantity" %}</th>
<th>{% trans "Minimum Quantity" %}</th>
</tr>
<tr style="height: 3rem">
<td style="text-align: center">{{ part_name }}</td>
<td style="text-align: center">{{ part_quantity }}</td>
<td style="text-align: center">{{ minimum_quantity }}</td>
</tr>
<tr style="background-color: aliceblue;height: 4rem;">
<td colspan="3" style="padding-top:1rem; text-align: center">{% trans "You are receiving this mail because you have starred the part " %} {{ part_name }}
{% trans "Inventree application" %}
</td>
</tr>
</table>