mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Serial number placeholder text for BuildComplete form
This commit is contained in:
parent
6552d011a4
commit
7190a8ef69
@ -34,6 +34,10 @@ class HelperForm(forms.ModelForm):
|
||||
Simply create a 'blank' layout for each available field.
|
||||
"""
|
||||
|
||||
self.rebuild_layout()
|
||||
|
||||
def rebuild_layout(self):
|
||||
|
||||
layouts = []
|
||||
|
||||
for field in self.fields:
|
||||
|
@ -46,6 +46,13 @@ class ConfirmBuildForm(HelperForm):
|
||||
class CompleteBuildForm(HelperForm):
|
||||
""" Form for marking a Build as complete """
|
||||
|
||||
field_prefix = {
|
||||
'serial_numbers': 'fa-hashtag',
|
||||
}
|
||||
|
||||
field_placeholder = {
|
||||
}
|
||||
|
||||
location = forms.ModelChoiceField(
|
||||
queryset=StockLocation.objects.all(),
|
||||
help_text='Location of completed parts',
|
||||
|
@ -53,6 +53,19 @@ class Build(MPTTModel):
|
||||
def get_absolute_url(self):
|
||||
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(
|
||||
verbose_name=_('Build Title'),
|
||||
blank=False,
|
||||
|
@ -196,6 +196,20 @@ class BuildComplete(AjaxUpdateView):
|
||||
|
||||
if not build.part.trackable:
|
||||
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
|
||||
|
||||
@ -208,6 +222,7 @@ class BuildComplete(AjaxUpdateView):
|
||||
initials = super(BuildComplete, self).get_initial().copy()
|
||||
|
||||
build = self.get_object()
|
||||
|
||||
if build.part.default_location is not None:
|
||||
try:
|
||||
location = StockLocation.objects.get(pk=build.part.default_location.id)
|
||||
|
@ -876,6 +876,8 @@ class StockItemCreate(AjaxCreateView):
|
||||
sn = part.getNextSerialNumber()
|
||||
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)
|
||||
form.fields['part'].widget = HiddenInput()
|
||||
|
||||
@ -998,6 +1000,8 @@ class StockItemCreate(AjaxCreateView):
|
||||
sn = part.getNextSerialNumber()
|
||||
form.field_placeholder['serial_numbers'] = _("Next available serial number is") + " " + str(sn)
|
||||
|
||||
form.rebuild_layout()
|
||||
|
||||
except (Part.DoesNotExist, ValueError, InvalidOperation):
|
||||
part = None
|
||||
quantity = 1
|
||||
|
Loading…
Reference in New Issue
Block a user