mirror of
https://github.com/inventree/InvenTree.git
synced 2026-03-13 07:33:36 +00:00
Refactor part.on_order (#11496)
More intelligent DB querying for significant speed improvement
This commit is contained in:
@@ -2582,21 +2582,22 @@ class Part(
|
|||||||
Note that some supplier parts may have a different pack_quantity attribute,
|
Note that some supplier parts may have a different pack_quantity attribute,
|
||||||
and this needs to be taken into account!
|
and this needs to be taken into account!
|
||||||
"""
|
"""
|
||||||
|
from order.models import PurchaseOrderLineItem
|
||||||
|
|
||||||
quantity = 0
|
quantity = 0
|
||||||
|
|
||||||
# Iterate through all supplier parts
|
# Find all outstanding PurchaseOrderLineItem objects which reference this part
|
||||||
for sp in self.supplier_parts.all():
|
lines = PurchaseOrderLineItem.objects.filter(
|
||||||
# Look at any incomplete line item for open orders
|
|
||||||
lines = sp.purchase_order_line_items.filter(
|
|
||||||
order__status__in=PurchaseOrderStatusGroups.OPEN,
|
order__status__in=PurchaseOrderStatusGroups.OPEN,
|
||||||
|
part__part_id=self.pk,
|
||||||
quantity__gt=F('received'),
|
quantity__gt=F('received'),
|
||||||
)
|
).prefetch_related('part')
|
||||||
|
|
||||||
for line in lines:
|
for line in lines:
|
||||||
remaining = line.quantity - line.received
|
remaining = line.quantity - line.received
|
||||||
|
|
||||||
if remaining > 0:
|
if remaining > 0:
|
||||||
quantity += sp.base_quantity(remaining)
|
quantity += line.part.base_quantity(remaining)
|
||||||
|
|
||||||
return quantity
|
return quantity
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user