mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Custom cleaning for form
Ok, looks like I've been doing this wrong the whole time! The "djangonic" way is pretty cool
This commit is contained in:
parent
a686500df1
commit
45c888e13d
@ -9,6 +9,7 @@ from django import forms
|
||||
from django.forms.utils import ErrorDict
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.core.validators import MinValueValidator
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from mptt.fields import TreeNodeChoiceField
|
||||
|
||||
@ -293,13 +294,33 @@ class InstallStockForm(HelperForm):
|
||||
]
|
||||
)
|
||||
|
||||
notes = forms.CharField(
|
||||
required=False,
|
||||
help_text=_('Notes')
|
||||
)
|
||||
|
||||
class Meta:
|
||||
model = StockItem
|
||||
fields = [
|
||||
'stock_item',
|
||||
'quantity_to_install',
|
||||
'notes',
|
||||
]
|
||||
|
||||
def clean(self):
|
||||
|
||||
data = super().clean()
|
||||
|
||||
print("Data:", data)
|
||||
|
||||
stock_item = data['stock_item']
|
||||
quantity = data['quantity_to_install']
|
||||
|
||||
if quantity > stock_item.quantity:
|
||||
raise ValidationError({'quantity_to_install': _('Must not exceed available quantity')})
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class UninstallStockForm(forms.ModelForm):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user