Various form fixes

- Updating forms, a lot has changed!
This commit is contained in:
Oliver Walters 2020-11-03 16:21:40 +11:00
parent 152801f06f
commit b936f67d87
6 changed files with 16 additions and 46 deletions

View File

@ -340,7 +340,6 @@ class Build(MPTTModel):
# which point to thie Build Order # which point to thie Build Order
self.allocated_stock.all().delete() self.allocated_stock.all().delete()
@transaction.atomic @transaction.atomic
def cancelBuild(self, user): def cancelBuild(self, user):
""" Mark the Build as CANCELLED """ Mark the Build as CANCELLED
@ -503,7 +502,7 @@ class Build(MPTTModel):
else: else:
serial = None serial = None
output = StockModels.StockItem.objects.create( StockModels.StockItem.objects.create(
quantity=1, quantity=1,
location=location, location=location,
part=self.part, part=self.part,
@ -518,7 +517,7 @@ class Build(MPTTModel):
Create a single build output of the given quantity Create a single build output of the given quantity
""" """
output = StockModels.StockItem.objects.create( StockModels.StockItem.objects.create(
quantity=quantity, quantity=quantity,
location=location, location=location,
part=self.part, part=self.part,
@ -527,7 +526,6 @@ class Build(MPTTModel):
is_building=True is_building=True
) )
@transaction.atomic @transaction.atomic
def deleteBuildOutput(self, output): def deleteBuildOutput(self, output):
""" """
@ -602,7 +600,6 @@ class Build(MPTTModel):
# REF: https://www.botreetechnologies.com/blog/implementing-celery-using-django-for-background-task-processing # REF: https://www.botreetechnologies.com/blog/implementing-celery-using-django-for-background-task-processing
# REF: https://code.tutsplus.com/tutorials/using-celery-with-django-for-background-task-processing--cms-28732 # REF: https://code.tutsplus.com/tutorials/using-celery-with-django-for-background-task-processing--cms-28732
# Complete the allocation of stock for that item # Complete the allocation of stock for that item
build_item.complete_allocation(user) build_item.complete_allocation(user)

View File

@ -16,7 +16,7 @@
{% if item.serial %} {% if item.serial %}
# {{ item.serial }} # {{ item.serial }}
{% else %} {% else %}
{{ item.quantity }} {% decimal item.quantity %}
{% endif %} {% endif %}
</div> </div>
</a> </a>

View File

@ -240,7 +240,6 @@ class BuildOutputCreate(AjaxUpdateView):
batch=batch, batch=batch,
) )
def get_initial(self): def get_initial(self):
initials = super().get_initial() initials = super().get_initial()
@ -262,7 +261,7 @@ class BuildOutputCreate(AjaxUpdateView):
# If the part is not trackable, hide the serial number input # If the part is not trackable, hide the serial number input
if not part.trackable: if not part.trackable:
form.fields['serial_numbers'] = HiddenInput() form.fields['serial_numbers'].widget = HiddenInput()
return form return form
@ -655,11 +654,7 @@ class BuildCreate(AjaxCreateView):
form = super().get_form() form = super().get_form()
if form['part'].value(): if form['part'].value():
part = Part.objects.get(pk=form['part'].value()) form.fields['part'].widget = HiddenInput()
# Part is not trackable - hide serial numbers
if not part.trackable:
form.fields['serial_numbers'].widget = HiddenInput()
return form return form
@ -699,7 +694,7 @@ class BuildCreate(AjaxCreateView):
'success': _('Created new build'), 'success': _('Created new build'),
} }
def validate(self, request, form, cleaned_data, **kwargs): def validate(self, build, form, **kwargs):
""" """
Perform extra form validation. Perform extra form validation.
@ -708,34 +703,7 @@ class BuildCreate(AjaxCreateView):
By this point form.is_valid() has been executed By this point form.is_valid() has been executed
""" """
part = cleaned_data['part'] pass
if part.trackable:
# For a trackable part, either batch or serial nubmber must be specified
if not cleaned_data['serial_numbers']:
form.add_error('serial_numbers', _('Trackable part must have serial numbers specified'))
else:
# If serial numbers are set...
serials = cleaned_data['serial_numbers']
quantity = cleaned_data['quantity']
# Check that the provided serial numbers are sensible
try:
extracted = extract_serial_numbers(serials, quantity)
except ValidationError as e:
extracted = None
form.add_error('serial_numbers', e.messages)
if extracted:
# Check that the provided serial numbers are not duplicates
conflicts = part.find_conflicting_serial_numbers(extracted)
if len(conflicts) > 0:
msg = ",".join([str(c) for c in conflicts])
form.add_error(
'serial_numbers',
_('Serial numbers already exist') + ': ' + msg
)
class BuildUpdate(AjaxUpdateView): class BuildUpdate(AjaxUpdateView):

View File

@ -10,7 +10,8 @@
{% include 'part/tabs.html' with tab='bom' %} {% include 'part/tabs.html' with tab='bom' %}
<h3>{% trans "Bill of Materials" %}</h3> <h4>{% trans "Bill of Materials" %}</h4>
<hr>
{% if part.bom_checked_date %} {% if part.bom_checked_date %}
{% if part.is_bom_valid %} {% if part.is_bom_valid %}

View File

@ -5,7 +5,8 @@
{% include 'part/tabs.html' with tab='build' %} {% include 'part/tabs.html' with tab='build' %}
<h3>{% trans "Part Builds" %}</h3> <h4>{% trans "Part Builds" %}</h4>
<hr>
<div id='button-toolbar'> <div id='button-toolbar'>
<div class='button-toolbar container-flui' style='float: right';> <div class='button-toolbar container-flui' style='float: right';>

View File

@ -648,9 +648,12 @@ function loadBuildTable(table, options) {
sortable: true, sortable: true,
formatter: function(value, row, index, field) { formatter: function(value, row, index, field) {
var name = row.part_detail.full_name; var html = imageHoverIcon(row.part_detail.thumbnail);
return imageHoverIcon(row.part_detail.thumbnail) + renderLink(name, '/part/' + row.part + '/'); html += renderLink(row.part_detail.full_name, `/part/${row.part}/`);
html += makePartIcons(row.part_detail);
return html;
} }
}, },
{ {