From 4420557863d706b2e130ac652e84c118a1523037 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 20 Apr 2021 13:54:19 +1000 Subject: [PATCH] Refactor various functions for assessing build allocation --- InvenTree/build/models.py | 39 ++++++++++++------- .../templates/build/complete_output.html | 11 ++++-- InvenTree/build/views.py | 2 +- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 963401a543..61beba3262 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -790,12 +790,13 @@ class Build(MPTTModel): # List the allocated BuildItem objects for the given output 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: # 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... - # 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 + # TODO: Use the background worker process to handle this task! # Complete the allocation of stock for that item build_item.complete_allocation(user) @@ -899,7 +900,13 @@ class Build(MPTTModel): 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 if not self.isPartFullyAllocated(part, output): @@ -915,7 +922,13 @@ class Build(MPTTModel): 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 if self.isPartFullyAllocated(part, output): @@ -930,17 +943,15 @@ class Build(MPTTModel): 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 - # 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): unallocated.append(part) diff --git a/InvenTree/build/templates/build/complete_output.html b/InvenTree/build/templates/build/complete_output.html index 806677c50c..3436aea8de 100644 --- a/InvenTree/build/templates/build/complete_output.html +++ b/InvenTree/build/templates/build/complete_output.html @@ -4,9 +4,10 @@ {% block pre_form_content %} -{% if fully_allocated %} -
-

{% trans "Stock allocation is complete" %}

+{% if not build.has_tracked_bom_items %} +{% elif fully_allocated %} +
+ {% trans "Stock allocation is complete for this output" %}
{% else %}
@@ -41,7 +42,11 @@
{% 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 }} + {% endif %}
diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 8f5141812f..5b9e0a3557 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -419,7 +419,7 @@ class BuildOutputComplete(AjaxUpdateView): View to mark a particular build output as Complete. - 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 """