mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Automagically disable 'serial_numbers' field for StockItemCreate form
- Yay, ajax magic!
This commit is contained in:
parent
2e4613e702
commit
652c2dbcbe
@ -108,7 +108,7 @@ class ConvertStockItemForm(HelperForm):
|
|||||||
class CreateStockItemForm(HelperForm):
|
class CreateStockItemForm(HelperForm):
|
||||||
""" Form for creating a new StockItem """
|
""" Form for creating a new StockItem """
|
||||||
|
|
||||||
serial_numbers = forms.CharField(label='Serial numbers', required=False, help_text=_('Enter unique serial numbers (or leave blank)'))
|
serial_numbers = forms.CharField(label=_('Serial numbers'), required=False, help_text=_('Enter unique serial numbers (or leave blank)'))
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
||||||
|
@ -1510,11 +1510,8 @@ class StockItemCreate(AjaxCreateView):
|
|||||||
# form.fields['part'].widget = HiddenInput()
|
# form.fields['part'].widget = HiddenInput()
|
||||||
|
|
||||||
# Trackable parts get special consideration:
|
# Trackable parts get special consideration:
|
||||||
if part.trackable:
|
form.fields['delete_on_deplete'].disabled = not part.trackable
|
||||||
form.fields['delete_on_deplete'].widget = HiddenInput()
|
form.fields['serial_numbers'].disabled = not part.trackable
|
||||||
form.fields['delete_on_deplete'].initial = False
|
|
||||||
else:
|
|
||||||
form.fields['serial_numbers'].widget = HiddenInput()
|
|
||||||
|
|
||||||
# If the part is NOT purchaseable, hide the supplier_part field
|
# If the part is NOT purchaseable, hide the supplier_part field
|
||||||
if not part.purchaseable:
|
if not part.purchaseable:
|
||||||
@ -1539,6 +1536,8 @@ class StockItemCreate(AjaxCreateView):
|
|||||||
# We must not provide *any* options for SupplierPart
|
# We must not provide *any* options for SupplierPart
|
||||||
form.fields['supplier_part'].queryset = SupplierPart.objects.none()
|
form.fields['supplier_part'].queryset = SupplierPart.objects.none()
|
||||||
|
|
||||||
|
form.fields['serial_numbers'].disabled = True
|
||||||
|
|
||||||
# Otherwise if the user has selected a SupplierPart, we know what Part they meant!
|
# Otherwise if the user has selected a SupplierPart, we know what Part they meant!
|
||||||
if form['supplier_part'].value() is not None:
|
if form['supplier_part'].value() is not None:
|
||||||
pass
|
pass
|
||||||
|
@ -769,6 +769,7 @@ function createNewStockItem(options) {
|
|||||||
field: 'part',
|
field: 'part',
|
||||||
action: function(value) {
|
action: function(value) {
|
||||||
|
|
||||||
|
// Reload options for supplier part
|
||||||
reloadFieldOptions(
|
reloadFieldOptions(
|
||||||
'supplier_part',
|
'supplier_part',
|
||||||
{
|
{
|
||||||
@ -782,6 +783,18 @@ function createNewStockItem(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Disable serial number field if the part is not trackable
|
||||||
|
inventreeGet(
|
||||||
|
`/api/part/${value}/`, {},
|
||||||
|
{
|
||||||
|
success: function(response) {
|
||||||
|
|
||||||
|
enableField('serial_numbers', response.trackable);
|
||||||
|
clearField('serial_numbers');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user