Adds ability to specify "status" of a build output at time of completion

This commit is contained in:
Oliver Walters 2021-04-21 14:57:30 +10:00
parent 0722aea58a
commit 9b763ca715
3 changed files with 24 additions and 2 deletions

View File

@ -12,6 +12,8 @@ from InvenTree.forms import HelperForm
from InvenTree.fields import RoundingDecimalFormField from InvenTree.fields import RoundingDecimalFormField
from InvenTree.fields import DatePickerFormField from InvenTree.fields import DatePickerFormField
from InvenTree.status_codes import StockStatus
from .models import Build, BuildItem, BuildOrderAttachment from .models import Build, BuildItem, BuildOrderAttachment
from stock.models import StockLocation, StockItem from stock.models import StockLocation, StockItem
@ -208,6 +210,13 @@ class CompleteBuildOutputForm(HelperForm):
help_text=_('Location of completed parts'), 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( confirm_incomplete = forms.BooleanField(
required=False, required=False,
label=_('Confirm incomplete'), label=_('Confirm incomplete'),
@ -226,10 +235,14 @@ class CompleteBuildOutputForm(HelperForm):
fields = [ fields = [
'location', 'location',
'output', 'output',
'stock_status',
'confirm', 'confirm',
'confirm_incomplete', 'confirm_incomplete',
] ]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
class CancelBuildForm(HelperForm): class CancelBuildForm(HelperForm):
""" Form for cancelling a build """ """ Form for cancelling a build """

View File

@ -22,7 +22,7 @@ from markdownx.models import MarkdownxField
from mptt.models import MPTTModel, TreeForeignKey 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.helpers import increment, getSetting, normalize, MakeBarcode
from InvenTree.validators import validate_build_order_reference from InvenTree.validators import validate_build_order_reference
from InvenTree.models import InvenTreeAttachment from InvenTree.models import InvenTreeAttachment
@ -810,6 +810,7 @@ class Build(MPTTModel):
# Select the location for the build output # Select the location for the build output
location = kwargs.get('location', self.destination) location = kwargs.get('location', self.destination)
status = kwargs.get('status', StockStatus.OK)
# 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()
@ -829,6 +830,7 @@ class Build(MPTTModel):
output.build = self output.build = self
output.is_building = False output.is_building = False
output.location = location output.location = location
output.status = status
output.save() output.save()

View File

@ -19,7 +19,7 @@ from stock.models import StockLocation, StockItem
from InvenTree.views import AjaxUpdateView, AjaxCreateView, AjaxDeleteView from InvenTree.views import AjaxUpdateView, AjaxCreateView, AjaxDeleteView
from InvenTree.views import InvenTreeRoleMixin from InvenTree.views import InvenTreeRoleMixin
from InvenTree.helpers import str2bool, extract_serial_numbers, normalize, isNull 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): class BuildIndex(InvenTreeRoleMixin, ListView):
@ -454,6 +454,11 @@ class BuildOutputComplete(AjaxUpdateView):
output = data.get('output', None) 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: if output:
quantity = data.get('quantity', None) quantity = data.get('quantity', None)
@ -545,12 +550,14 @@ class BuildOutputComplete(AjaxUpdateView):
location = data.get('location', None) location = data.get('location', None)
output = data.get('output', None) output = data.get('output', None)
stock_status = data.get('stock_status', StockStatus.OK)
# Complete the build output # Complete the build output
build.completeBuildOutput( build.completeBuildOutput(
output, output,
self.request.user, self.request.user,
location=location, location=location,
status=stock_status,
) )
def get_data(self): def get_data(self):