Serial number placeholder text for BuildComplete form

This commit is contained in:
Oliver Walters 2020-05-16 17:29:41 +10:00
parent 6552d011a4
commit 7190a8ef69
5 changed files with 43 additions and 0 deletions

View File

@ -34,6 +34,10 @@ class HelperForm(forms.ModelForm):
Simply create a 'blank' layout for each available field. Simply create a 'blank' layout for each available field.
""" """
self.rebuild_layout()
def rebuild_layout(self):
layouts = [] layouts = []
for field in self.fields: for field in self.fields:

View File

@ -46,6 +46,13 @@ class ConfirmBuildForm(HelperForm):
class CompleteBuildForm(HelperForm): class CompleteBuildForm(HelperForm):
""" Form for marking a Build as complete """ """ Form for marking a Build as complete """
field_prefix = {
'serial_numbers': 'fa-hashtag',
}
field_placeholder = {
}
location = forms.ModelChoiceField( location = forms.ModelChoiceField(
queryset=StockLocation.objects.all(), queryset=StockLocation.objects.all(),
help_text='Location of completed parts', help_text='Location of completed parts',

View File

@ -53,6 +53,19 @@ class Build(MPTTModel):
def get_absolute_url(self): def get_absolute_url(self):
return reverse('build-detail', kwargs={'pk': self.id}) return reverse('build-detail', kwargs={'pk': self.id})
def clean(self):
"""
Validation for Build object.
"""
super().clean()
if self.part.trackable:
if not self.quantity == int(self.quantity):
raise ValidationError({
'quantity': _("Build quantity must be integer value for trackable parts")
})
title = models.CharField( title = models.CharField(
verbose_name=_('Build Title'), verbose_name=_('Build Title'),
blank=False, blank=False,

View File

@ -196,6 +196,20 @@ class BuildComplete(AjaxUpdateView):
if not build.part.trackable: if not build.part.trackable:
form.fields.pop('serial_numbers') form.fields.pop('serial_numbers')
else:
sn = build.part.getNextSerialNumber()
if build.quantity > 1:
sn = "{n}-{m}".format(
n=str(sn),
m=str(sn+build.quantity-1)
)
else:
sn = str(sn)
form.field_placeholder['serial_numbers'] = sn
form.rebuild_layout()
return form return form
@ -208,6 +222,7 @@ class BuildComplete(AjaxUpdateView):
initials = super(BuildComplete, self).get_initial().copy() initials = super(BuildComplete, self).get_initial().copy()
build = self.get_object() build = self.get_object()
if build.part.default_location is not None: if build.part.default_location is not None:
try: try:
location = StockLocation.objects.get(pk=build.part.default_location.id) location = StockLocation.objects.get(pk=build.part.default_location.id)

View File

@ -876,6 +876,8 @@ class StockItemCreate(AjaxCreateView):
sn = part.getNextSerialNumber() sn = part.getNextSerialNumber()
form.field_placeholder['serial_numbers'] = _('Next available serial number is') + ' ' + str(sn) form.field_placeholder['serial_numbers'] = _('Next available serial number is') + ' ' + str(sn)
form.rebuild_layout()
# Hide the 'part' field (as a valid part is selected) # Hide the 'part' field (as a valid part is selected)
form.fields['part'].widget = HiddenInput() form.fields['part'].widget = HiddenInput()
@ -998,6 +1000,8 @@ class StockItemCreate(AjaxCreateView):
sn = part.getNextSerialNumber() sn = part.getNextSerialNumber()
form.field_placeholder['serial_numbers'] = _("Next available serial number is") + " " + str(sn) form.field_placeholder['serial_numbers'] = _("Next available serial number is") + " " + str(sn)
form.rebuild_layout()
except (Part.DoesNotExist, ValueError, InvalidOperation): except (Part.DoesNotExist, ValueError, InvalidOperation):
part = None part = None
quantity = 1 quantity = 1