2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-19 21:45:39 +00:00

Added post_delete hook to StockItem

moved the business logic of 'deciding if a low stock notification has to be sent' to part.tasks
This commit is contained in:
rocheparadox
2021-11-01 08:25:59 +05:30
parent 60c2aab06d
commit 76c1e936db
2 changed files with 26 additions and 9 deletions

View File

@ -37,3 +37,16 @@ def notify_low_stock(part: Part):
html_message = render_to_string('stock/low_stock_notification.html', context)
recipients = starred_users_email.values_list('email', flat=True)
inventree_tasks.send_email(subject, '', recipients, html_message=html_message)
def notify_low_stock_if_required(part: Part):
"""
Check if the stock quantity has fallen below the minimum threshold of part. If yes, notify the users who have
starred the part
"""
if part.is_part_low_on_stock():
inventree_tasks.offload_task(
'part.tasks.notify_low_stock',
part
)