mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Add function for required build order quantity
This commit is contained in:
parent
d2c9f759b1
commit
cda97829ab
@ -884,6 +884,62 @@ class Part(MPTTModel):
|
||||
|
||||
return max(total, 0)
|
||||
|
||||
def requiring_build_orders(self):
|
||||
"""
|
||||
Return list of outstanding build orders which require this part
|
||||
"""
|
||||
|
||||
# List of BOM that this part is required for
|
||||
boms = BomItem.objects.filter(sub_part=self)
|
||||
|
||||
part_ids = [bom.part.pk for bom in boms]
|
||||
|
||||
# Now, get a list of outstanding build orders which require this part
|
||||
builds = BuildModels.Build.objects.filter(
|
||||
part__in=part_ids,
|
||||
status__in=BuildStatus.ACTIVE_CODES
|
||||
)
|
||||
|
||||
return builds
|
||||
|
||||
def required_build_order_quantity(self):
|
||||
"""
|
||||
Return the quantity of this part required for active build orders
|
||||
"""
|
||||
|
||||
# List of BOM that this part is required for
|
||||
boms = BomItem.objects.filter(sub_part=self)
|
||||
|
||||
part_ids = [bom.part.pk for bom in boms]
|
||||
|
||||
# Now, get a list of outstanding build orders which require this part
|
||||
builds = BuildModels.Build.objects.filter(
|
||||
part__in=part_ids,
|
||||
status__in=BuildStatus.ACTIVE_CODES
|
||||
)
|
||||
|
||||
quantity = 0
|
||||
|
||||
for build in builds:
|
||||
|
||||
bom_item = None
|
||||
|
||||
# Match BOM item to build
|
||||
for bom in boms:
|
||||
if bom.part == build.part:
|
||||
bom_item = bom
|
||||
break
|
||||
|
||||
if bom_item is None:
|
||||
logger.warning("Found null BomItem when calculating required quantity")
|
||||
continue
|
||||
|
||||
build_quantity = build.quantity * bom_item.quantity
|
||||
|
||||
quantity += build_quantity
|
||||
|
||||
return quantity
|
||||
|
||||
@property
|
||||
def quantity_to_order(self):
|
||||
""" Return the quantity needing to be ordered for this part. """
|
||||
|
@ -127,6 +127,13 @@
|
||||
<td>{% include "part/stock_count.html" %}</td>
|
||||
</tr>
|
||||
{% if not part.is_template %}
|
||||
{% if part.required_build_order_quantity > 0 %}
|
||||
<tr>
|
||||
<td><span class='fas fa-hand-holding'></span></td>
|
||||
<td>{% trans "Required for Build Orders" %}</td>
|
||||
<td>{% decimal part.required_build_order_quantity %}</td>
|
||||
</tr>
|
||||
{% endif %}
|
||||
{% if part.build_order_allocation_count > 0 %}
|
||||
<tr>
|
||||
<td><span class='fas fa-dolly'></span></td>
|
||||
|
Loading…
Reference in New Issue
Block a user