diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 6ef455aa70..2124207c7d 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -197,17 +197,12 @@ 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) - ) + if build.quantity == 1: + text = _('Next available serial number is') else: - sn = str(sn) - - form.field_placeholder['serial_numbers'] = sn + text = _('Next available serial numbers are') + + form.field_placeholder['serial_numbers'] = text + " " + build.part.getSerialNumberString(build.quantity) form.rebuild_layout() diff --git a/InvenTree/order/forms.py b/InvenTree/order/forms.py index 2887ef8892..ca61bd77be 100644 --- a/InvenTree/order/forms.py +++ b/InvenTree/order/forms.py @@ -8,9 +8,6 @@ from __future__ import unicode_literals from django import forms from django.utils.translation import ugettext as _ -from crispy_forms.layout import Field, Layout -from crispy_forms.bootstrap import PrependedText - from mptt.fields import TreeNodeChoiceField from InvenTree.forms import HelperForm diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 31771dc291..7639b9c25b 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -308,6 +308,24 @@ class Part(MPTTModel): else: return n + 1 + def getSerialNumberString(self, quantity): + """ + Return a formatted string representing the next available serial numbers, + given a certain quantity of items. + """ + + sn = self.getNextSerialNumber() + + if quantity >= 2: + sn = "{n}-{m}".format( + n=sn, + m=int(sn + quantity - 1) + ) + else: + sn = str(sn) + + return sn + @property def full_name(self): """ Format a 'full name' for this Part. diff --git a/InvenTree/stock/forms.py b/InvenTree/stock/forms.py index 520ac72835..98a4de56d6 100644 --- a/InvenTree/stock/forms.py +++ b/InvenTree/stock/forms.py @@ -9,9 +9,6 @@ from django import forms from django.forms.utils import ErrorDict from django.utils.translation import ugettext as _ -from crispy_forms.layout import Field, Layout -from crispy_forms.bootstrap import PrependedText - from mptt.fields import TreeNodeChoiceField from InvenTree.helpers import GetExportFormats @@ -111,23 +108,7 @@ class SerializeStockForm(HelperForm): item = kwargs.pop('item', None) if item: - - # Pre-calculate what the serial numbers should be! - sn = item.part.getNextSerialNumber() - - if item.quantity >= 2: - sn = "{n}-{m}".format(n=sn, m=int(sn+item.quantity-1)) - else: - sn = str(sn) - - - self.field_placeholder = { - 'serial_numbers': sn - } - - self.field_prefix = { - 'serial_numbers': 'fa-hashtag', - } + self.field_placeholder['serial_numbers'] = item.part.getSerialNumberString(item.quantity) super().__init__(*args, **kwargs) diff --git a/InvenTree/stock/tests.py b/InvenTree/stock/tests.py index ab038c3c62..edb9660000 100644 --- a/InvenTree/stock/tests.py +++ b/InvenTree/stock/tests.py @@ -308,7 +308,6 @@ class StockTest(TestCase): item.delete_on_deplete = True item.save() - n = StockItem.objects.filter(part=25).count() self.assertEqual(item.quantity, 10) diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index b096f2a24f..dc70cc6bfb 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -755,7 +755,7 @@ class StockItemSerialize(AjaxUpdateView): model = StockItem ajax_template_name = 'stock/item_serialize.html' ajax_form_title = _('Serialize Stock') - #form_class = SerializeStockForm + form_class = SerializeStockForm def get_form(self): @@ -774,16 +774,8 @@ class StockItemSerialize(AjaxUpdateView): item = self.get_object() - # Pre-calculate what the serial numbers should be! - sn = item.part.getNextSerialNumber() - - if item.quantity >= 2: - sn = "{n}-{m}".format(n=sn, m=int(sn+item.quantity-1)) - else: - sn = str(sn) - initials['quantity'] = item.quantity - initials['serial_numbers'] = sn + initials['serial_numbers'] = item.part.getSerialNumberString(item.quantity) initials['destination'] = item.location.pk return initials