From 9b763ca7150c265f1699c276c0fd42f311f4a627 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 21 Apr 2021 14:57:30 +1000 Subject: [PATCH] Adds ability to specify "status" of a build output at time of completion --- InvenTree/build/forms.py | 13 +++++++++++++ InvenTree/build/models.py | 4 +++- InvenTree/build/views.py | 9 ++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/InvenTree/build/forms.py b/InvenTree/build/forms.py index d4f5e23ce7..be325bb467 100644 --- a/InvenTree/build/forms.py +++ b/InvenTree/build/forms.py @@ -12,6 +12,8 @@ from InvenTree.forms import HelperForm from InvenTree.fields import RoundingDecimalFormField from InvenTree.fields import DatePickerFormField +from InvenTree.status_codes import StockStatus + from .models import Build, BuildItem, BuildOrderAttachment from stock.models import StockLocation, StockItem @@ -208,6 +210,13 @@ class CompleteBuildOutputForm(HelperForm): help_text=_('Location of completed parts'), ) + stock_status = forms.ChoiceField( + label=_('Status'), + help_text=_('Build output stock status'), + initial=StockStatus.OK, + choices=StockStatus.items(), + ) + confirm_incomplete = forms.BooleanField( required=False, label=_('Confirm incomplete'), @@ -226,10 +235,14 @@ class CompleteBuildOutputForm(HelperForm): fields = [ 'location', 'output', + 'stock_status', 'confirm', 'confirm_incomplete', ] + def __init__(self, *args, **kwargs): + + super().__init__(*args, **kwargs) class CancelBuildForm(HelperForm): """ Form for cancelling a build """ diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index d68064bed4..16c0e5bb7f 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -22,7 +22,7 @@ from markdownx.models import MarkdownxField from mptt.models import MPTTModel, TreeForeignKey -from InvenTree.status_codes import BuildStatus +from InvenTree.status_codes import BuildStatus, StockStatus from InvenTree.helpers import increment, getSetting, normalize, MakeBarcode from InvenTree.validators import validate_build_order_reference from InvenTree.models import InvenTreeAttachment @@ -810,6 +810,7 @@ class Build(MPTTModel): # Select the location for the build output location = kwargs.get('location', self.destination) + status = kwargs.get('status', StockStatus.OK) # List the allocated BuildItem objects for the given output allocated_items = output.items_to_install.all() @@ -829,6 +830,7 @@ class Build(MPTTModel): output.build = self output.is_building = False output.location = location + output.status = status output.save() diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 7e27c1bc64..0c9cc62370 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -19,7 +19,7 @@ from stock.models import StockLocation, StockItem from InvenTree.views import AjaxUpdateView, AjaxCreateView, AjaxDeleteView from InvenTree.views import InvenTreeRoleMixin from InvenTree.helpers import str2bool, extract_serial_numbers, normalize, isNull -from InvenTree.status_codes import BuildStatus +from InvenTree.status_codes import BuildStatus, StockStatus class BuildIndex(InvenTreeRoleMixin, ListView): @@ -454,6 +454,11 @@ class BuildOutputComplete(AjaxUpdateView): output = data.get('output', None) + stock_status = data.get('stock_status', StockStatus.OK) + + if int(stock_status) not in StockStatus.keys(): + form.add_error('status', _('Invalid stock status value selected')) + if output: quantity = data.get('quantity', None) @@ -545,12 +550,14 @@ class BuildOutputComplete(AjaxUpdateView): location = data.get('location', None) output = data.get('output', None) + stock_status = data.get('stock_status', StockStatus.OK) # Complete the build output build.completeBuildOutput( output, self.request.user, location=location, + status=stock_status, ) def get_data(self):