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

Notify users who have starred a part when that part's stock quantity falls below the minimum quanitity/threshold through email.

This commit is contained in:
rocheparadox
2021-10-29 16:03:41 +05:30
parent 5cd9be6845
commit d8796f9535
3 changed files with 74 additions and 3 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
from django.dispatch import receiver
from markdownx.models import MarkdownxField
@ -36,6 +36,7 @@ import label.models
from InvenTree.status_codes import StockStatus, StockHistoryCode
from InvenTree.models import InvenTreeTree, InvenTreeAttachment
from InvenTree.fields import InvenTreeModelMoneyField, InvenTreeURLField
from InvenTree import tasks as inventree_tasks
from users.models import Owner
@ -1651,6 +1652,17 @@ def before_delete_stock_item(sender, instance, using, **kwargs):
child.save()
@receiver(post_save, sender=StockItem)
def after_save_stock_item(sender, instance: StockItem, **kwargs):
"""
Check if the stock quantity has fallen below the minimum threshold of part. If yes, notify the users who have
starred the part
"""
if instance.quantity <= instance.part.minimum_stock:
inventree_tasks.notify_low_stock(instance)
class StockItemAttachment(InvenTreeAttachment):
"""
Model for storing file attachments against a StockItem object.

View File

@ -0,0 +1,27 @@
<p>{{ message }}</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)">Part low on stock</th>
</tr>
<tr style="height: 3rem; border-bottom: 1px solid">
<th>Part Name</th>
<th>Available Quantity</th>
<th>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">You are receiving this mail because you have starred the part {{ part_name }} in
Inventree application</td>
</tr>
</table>