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

Add task to check required stock for build order

This commit is contained in:
Oliver
2021-11-04 13:32:14 +11:00
parent 8025dab69b
commit 6db6a70fc2
4 changed files with 135 additions and 6 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):
"""

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)