diff --git a/InvenTree/part/tasks.py b/InvenTree/part/tasks.py index 779027a96d..f4f1459214 100644 --- a/InvenTree/part/tasks.py +++ b/InvenTree/part/tasks.py @@ -2,13 +2,14 @@ from __future__ import unicode_literals import logging +from datetime import timedelta from django.utils.translation import ugettext_lazy as _ from django.template.loader import render_to_string from allauth.account.models import EmailAddress -from common.models import InvenTree +from common.models import NotificationEntry import InvenTree.helpers import InvenTree.tasks @@ -23,6 +24,13 @@ def notify_low_stock(part: part.models.Part): Notify users who have starred a part when its stock quantity falls below the minimum threshold """ + # Check if we have notified recently... + delta = timedelta(days=1) + + if NotificationEntry.check_recent('part.notify_low_stock', part.pk, delta): + logger.info(f"Low stock notification has recently been sent for '{part.full_name}' - SKIPPING") + return + logger.info(f"Sending low stock notification email for {part.full_name}") # Get a list of users who are subcribed to this part @@ -48,6 +56,8 @@ def notify_low_stock(part: part.models.Part): InvenTree.tasks.send_email(subject, '', recipients, html_message=html_message) + NotificationEntry.notify('part.notify_low_stock', part.pk) + def notify_low_stock_if_required(part: part.models.Part): """