mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Prevent low-stock notifications from overwhelming users
- Limit to once per day, per part
This commit is contained in:
parent
bebf368d06
commit
a447e22108
@ -2,13 +2,14 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
|
|
||||||
from allauth.account.models import EmailAddress
|
from allauth.account.models import EmailAddress
|
||||||
|
|
||||||
from common.models import InvenTree
|
from common.models import NotificationEntry
|
||||||
|
|
||||||
import InvenTree.helpers
|
import InvenTree.helpers
|
||||||
import InvenTree.tasks
|
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
|
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}")
|
logger.info(f"Sending low stock notification email for {part.full_name}")
|
||||||
|
|
||||||
# Get a list of users who are subcribed to this part
|
# 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)
|
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):
|
def notify_low_stock_if_required(part: part.models.Part):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user