2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 12:05:53 +00:00

Prevent calculation of 'allocation_count' before model is saved (#3235)

This commit is contained in:
Oliver
2022-06-22 20:50:21 +10:00
committed by GitHub
parent 63b4ff3eb6
commit 9b4e443289

View File

@ -1318,6 +1318,11 @@ class Part(MetadataMixin, MPTTModel):
def allocation_count(self, **kwargs): def allocation_count(self, **kwargs):
"""Return the total quantity of stock allocated for this part, against both build orders and sales orders.""" """Return the total quantity of stock allocated for this part, against both build orders and sales orders."""
if self.id is None:
# If this instance has not been saved, foreign-key lookups will fail
return 0
return sum( return sum(
[ [
self.build_order_allocation_count(**kwargs), self.build_order_allocation_count(**kwargs),