2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-13 02:25:38 +00:00
Files
InvenTree/InvenTree/part/tasks.py
Oliver Walters 99676eef6d Merge remote-tracking branch 'inventree/master' into docupdates
# Conflicts:
#	.github/workflows/qc_checks.yaml
#	InvenTree/InvenTree/version.py
#	InvenTree/common/notifications.py
#	InvenTree/label/api.py
#	InvenTree/plugin/base/label/label.py
#	InvenTree/plugin/base/label/mixins.py
#	InvenTree/plugin/base/label/test_label_mixin.py
#	InvenTree/plugin/registry.py
2022-05-30 20:10:27 +10:00

49 lines
1.4 KiB
Python

import logging
from django.utils.translation import gettext_lazy as _
import common.notifications
import InvenTree.helpers
import InvenTree.tasks
import part.models
logger = logging.getLogger("inventree")
def notify_low_stock(part: part.models.Part):
name = _("Low stock notification")
message = _(f'The available stock for {part.name} has fallen below the configured minimum level')
context = {
'part': part,
'name': name,
'message': message,
'link': InvenTree.helpers.construct_absolute_url(part.get_absolute_url()),
'template': {
'html': 'email/low_stock_notification.html',
'subject': "[InvenTree] " + name,
},
}
common.notifications.trigger_notification(
part,
'part.notify_low_stock',
target_fnc=part.get_subscribers,
context=context,
)
def notify_low_stock_if_required(part: part.models.Part):
"""Check if the stock quantity has fallen below the minimum threshold of part.
If true, notify the users who have subscribed to the part
"""
# Run "up" the tree, to allow notification for "parent" parts
parts = part.get_ancestors(include_self=True, ascending=True)
for p in parts:
if p.is_part_low_on_stock():
InvenTree.tasks.offload_task(
notify_low_stock,
p
)