Fix form validation

This commit is contained in:
Oliver Walters 2020-10-04 23:48:15 +11:00
parent 42a75a8238
commit 852da6d696
2 changed files with 4 additions and 6 deletions

View File

@ -282,7 +282,7 @@ class InstallStockForm(HelperForm):
part = forms.ModelChoiceField(
queryset=Part.objects.all(),
widget=forms.HiddenInput
widget=forms.HiddenInput()
)
stock_item = forms.ModelChoiceField(
@ -321,10 +321,10 @@ class InstallStockForm(HelperForm):
print("Data:", data)
stock_item = data['stock_item']
quantity = data['quantity_to_install']
stock_item = data.get('stock_item', None)
quantity = data.get('quantity_to_install', None)
if quantity > stock_item.quantity:
if stock_item and quantity and quantity > stock_item.quantity:
raise ValidationError({'quantity_to_install': _('Must not exceed available quantity')})
return data

View File

@ -1079,8 +1079,6 @@ function loadInstalledInTable(table, options) {
// The stock item did *not* match any items in the BOM!
// Add a new row to the table...
console.log("Found an unmatched part! " + item.pk + " -> " + item.part);
// Contruct a new "row" to add to the table
var new_row = {
sub_part: item.part,