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

Merge pull request #2246 from SchrodingersGat/build-order-notification

Build order notification
This commit is contained in:
Oliver
2021-11-04 15:23:39 +11:00
committed by GitHub
5 changed files with 175 additions and 16 deletions

View File

@ -1324,6 +1324,17 @@ class Part(MPTTModel):
return query
def get_stock_count(self, include_variants=True):
"""
Return the total "in stock" count for this part
"""
entries = self.stock_entries(in_stock=True, include_variants=include_variants)
query = entries.aggregate(t=Coalesce(Sum('quantity'), Decimal(0)))
return query['t']
@property
def total_stock(self):
""" Return the total stock quantity for this part.
@ -1332,11 +1343,7 @@ class Part(MPTTModel):
- If this part is a "template" (variants exist) then these are counted too
"""
entries = self.stock_entries(in_stock=True)
query = entries.aggregate(t=Coalesce(Sum('quantity'), Decimal(0)))
return query['t']
return self.get_stock_count()
def get_bom_item_filter(self, include_inherited=True):
"""
@ -2095,13 +2102,16 @@ class Part(MPTTModel):
@receiver(post_save, sender=Part, dispatch_uid='part_post_save_log')
def after_save_part(sender, instance: Part, **kwargs):
def after_save_part(sender, instance: Part, created, **kwargs):
"""
Function to be executed after a Part is saved
"""
# Run this check in the background
InvenTree.tasks.offload_task('part.tasks.notify_low_stock_if_required', instance)
if not created:
# Check part stock only if we are *updating* the part (not creating it)
# Run this check in the background
InvenTree.tasks.offload_task('part.tasks.notify_low_stock_if_required', instance)
def attach_file(instance, filename):

View File

@ -50,7 +50,7 @@ def notify_low_stock(part: part.models.Part):
'link': InvenTree.helpers.construct_absolute_url(part.get_absolute_url()),
}
subject = _(f'[InvenTree] {part.name} is low on stock')
subject = "[InvenTree] " + _("Low stock notification")
html_message = render_to_string('email/low_stock_notification.html', context)
recipients = emails.values_list('email', flat=True)