mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 13:06:45 +00:00
Refactor various functions for assessing build allocation
This commit is contained in:
parent
05e2b62305
commit
4420557863
@ -790,12 +790,13 @@ class Build(MPTTModel):
|
|||||||
# List the allocated BuildItem objects for the given output
|
# List the allocated BuildItem objects for the given output
|
||||||
allocated_items = output.items_to_install.all()
|
allocated_items = output.items_to_install.all()
|
||||||
|
|
||||||
|
# Ensure that only "trackable" parts are installed in the particular build output
|
||||||
|
allocated_items = allocated_items.filter(part__trackable=True)
|
||||||
|
|
||||||
for build_item in allocated_items:
|
for build_item in allocated_items:
|
||||||
|
|
||||||
# TODO: This is VERY SLOW as each deletion from the database takes ~1 second to complete
|
# TODO: This is VERY SLOW as each deletion from the database takes ~1 second to complete
|
||||||
# TODO: Use celery / redis to offload the actual object deletion...
|
# TODO: Use the background worker process to handle this task!
|
||||||
# REF: https://www.botreetechnologies.com/blog/implementing-celery-using-django-for-background-task-processing
|
|
||||||
# REF: https://code.tutsplus.com/tutorials/using-celery-with-django-for-background-task-processing--cms-28732
|
|
||||||
|
|
||||||
# Complete the allocation of stock for that item
|
# Complete the allocation of stock for that item
|
||||||
build_item.complete_allocation(user)
|
build_item.complete_allocation(user)
|
||||||
@ -899,7 +900,13 @@ class Build(MPTTModel):
|
|||||||
Returns True if the particular build output is fully allocated.
|
Returns True if the particular build output is fully allocated.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
for bom_item in self.bom_items:
|
# If output is not specified, we are talking about "untracked" items
|
||||||
|
if output is None:
|
||||||
|
bom_items = self.untracked_bom_items
|
||||||
|
else:
|
||||||
|
bom_items = self.tracked_bom_items
|
||||||
|
|
||||||
|
for bom_item in bom_items:
|
||||||
part = bom_item.sub_part
|
part = bom_item.sub_part
|
||||||
|
|
||||||
if not self.isPartFullyAllocated(part, output):
|
if not self.isPartFullyAllocated(part, output):
|
||||||
@ -915,7 +922,13 @@ class Build(MPTTModel):
|
|||||||
|
|
||||||
allocated = []
|
allocated = []
|
||||||
|
|
||||||
for bom_item in self.bom_items:
|
# If output is not specified, we are talking about "untracked" items
|
||||||
|
if output is None:
|
||||||
|
bom_items = self.untracked_bom_items
|
||||||
|
else:
|
||||||
|
bom_items = self.tracked_bom_items
|
||||||
|
|
||||||
|
for bom_item in bom_items:
|
||||||
part = bom_item.sub_part
|
part = bom_item.sub_part
|
||||||
|
|
||||||
if self.isPartFullyAllocated(part, output):
|
if self.isPartFullyAllocated(part, output):
|
||||||
@ -930,17 +943,15 @@ class Build(MPTTModel):
|
|||||||
|
|
||||||
unallocated = []
|
unallocated = []
|
||||||
|
|
||||||
for bom_item in self.bom_items:
|
# If output is not specified, we are talking about "untracked" items
|
||||||
|
if output is None:
|
||||||
|
bom_items = self.untracked_bom_items
|
||||||
|
else:
|
||||||
|
bom_items = self.tracked_bom_items
|
||||||
|
|
||||||
|
for bom_item in bom_items:
|
||||||
part = bom_item.sub_part
|
part = bom_item.sub_part
|
||||||
|
|
||||||
# Ignore "trackable" when output is specified
|
|
||||||
if output and not part.trackable:
|
|
||||||
continue
|
|
||||||
|
|
||||||
# Ignore "untrackable" parts when output is not specified
|
|
||||||
if not output and part.trackable:
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not self.isPartFullyAllocated(part, output):
|
if not self.isPartFullyAllocated(part, output):
|
||||||
unallocated.append(part)
|
unallocated.append(part)
|
||||||
|
|
||||||
|
@ -4,9 +4,10 @@
|
|||||||
|
|
||||||
{% block pre_form_content %}
|
{% block pre_form_content %}
|
||||||
|
|
||||||
{% if fully_allocated %}
|
{% if not build.has_tracked_bom_items %}
|
||||||
<div class='alert alert-block alert-info'>
|
{% elif fully_allocated %}
|
||||||
<h4>{% trans "Stock allocation is complete" %}</h4>
|
<div class='alert alert-block alert-success'>
|
||||||
|
{% trans "Stock allocation is complete for this output" %}
|
||||||
</div>
|
</div>
|
||||||
{% else %}
|
{% else %}
|
||||||
<div class='alert alert-block alert-danger'>
|
<div class='alert alert-block alert-danger'>
|
||||||
@ -41,7 +42,11 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class='panel-content'>
|
<div class='panel-content'>
|
||||||
{% include "hover_image.html" with image=build.part.image hover=True %}
|
{% include "hover_image.html" with image=build.part.image hover=True %}
|
||||||
|
{% if output.serialized %}
|
||||||
|
{{ output.part.full_name }} - {% trans "Serial Number" %} {{ output.serial }}
|
||||||
|
{% else %}
|
||||||
{% decimal output.quantity %} x {{ output.part.full_name }}
|
{% decimal output.quantity %} x {{ output.part.full_name }}
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ class BuildOutputComplete(AjaxUpdateView):
|
|||||||
View to mark a particular build output as Complete.
|
View to mark a particular build output as Complete.
|
||||||
|
|
||||||
- Notifies the user of which parts will be removed from stock.
|
- Notifies the user of which parts will be removed from stock.
|
||||||
- Removes allocated items from stock
|
- Assignes (tracked) allocated items from stock to the build output
|
||||||
- Deletes pending BuildItem objects
|
- Deletes pending BuildItem objects
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user