mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Various form fixes
- Updating forms, a lot has changed!
This commit is contained in:
@ -340,7 +340,6 @@ class Build(MPTTModel):
|
||||
# which point to thie Build Order
|
||||
self.allocated_stock.all().delete()
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
def cancelBuild(self, user):
|
||||
""" Mark the Build as CANCELLED
|
||||
@ -503,7 +502,7 @@ class Build(MPTTModel):
|
||||
else:
|
||||
serial = None
|
||||
|
||||
output = StockModels.StockItem.objects.create(
|
||||
StockModels.StockItem.objects.create(
|
||||
quantity=1,
|
||||
location=location,
|
||||
part=self.part,
|
||||
@ -518,7 +517,7 @@ class Build(MPTTModel):
|
||||
Create a single build output of the given quantity
|
||||
"""
|
||||
|
||||
output = StockModels.StockItem.objects.create(
|
||||
StockModels.StockItem.objects.create(
|
||||
quantity=quantity,
|
||||
location=location,
|
||||
part=self.part,
|
||||
@ -527,7 +526,6 @@ class Build(MPTTModel):
|
||||
is_building=True
|
||||
)
|
||||
|
||||
|
||||
@transaction.atomic
|
||||
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://code.tutsplus.com/tutorials/using-celery-with-django-for-background-task-processing--cms-28732
|
||||
|
||||
|
||||
# Complete the allocation of stock for that item
|
||||
build_item.complete_allocation(user)
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
{% if item.serial %}
|
||||
# {{ item.serial }}
|
||||
{% else %}
|
||||
{{ item.quantity }}
|
||||
{% decimal item.quantity %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</a>
|
||||
|
@ -240,7 +240,6 @@ class BuildOutputCreate(AjaxUpdateView):
|
||||
batch=batch,
|
||||
)
|
||||
|
||||
|
||||
def get_initial(self):
|
||||
|
||||
initials = super().get_initial()
|
||||
@ -262,7 +261,7 @@ class BuildOutputCreate(AjaxUpdateView):
|
||||
|
||||
# If the part is not trackable, hide the serial number input
|
||||
if not part.trackable:
|
||||
form.fields['serial_numbers'] = HiddenInput()
|
||||
form.fields['serial_numbers'].widget = HiddenInput()
|
||||
|
||||
return form
|
||||
|
||||
@ -655,11 +654,7 @@ class BuildCreate(AjaxCreateView):
|
||||
form = super().get_form()
|
||||
|
||||
if form['part'].value():
|
||||
part = Part.objects.get(pk=form['part'].value())
|
||||
|
||||
# Part is not trackable - hide serial numbers
|
||||
if not part.trackable:
|
||||
form.fields['serial_numbers'].widget = HiddenInput()
|
||||
form.fields['part'].widget = HiddenInput()
|
||||
|
||||
return form
|
||||
|
||||
@ -699,7 +694,7 @@ class BuildCreate(AjaxCreateView):
|
||||
'success': _('Created new build'),
|
||||
}
|
||||
|
||||
def validate(self, request, form, cleaned_data, **kwargs):
|
||||
def validate(self, build, form, **kwargs):
|
||||
"""
|
||||
Perform extra form validation.
|
||||
|
||||
@ -708,34 +703,7 @@ class BuildCreate(AjaxCreateView):
|
||||
By this point form.is_valid() has been executed
|
||||
"""
|
||||
|
||||
part = cleaned_data['part']
|
||||
|
||||
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
|
||||
)
|
||||
pass
|
||||
|
||||
|
||||
class BuildUpdate(AjaxUpdateView):
|
||||
|
Reference in New Issue
Block a user