mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-05 21:20:56 +00:00
Validate uniqueness for StockItems
- If the Part is a variant of a template, ensure that the serial numbers are unique across all instances of the template - Prevent instantiation of a StockItem for a part which has variants
This commit is contained in:
@ -208,28 +208,31 @@ class StockItemCreate(AjaxCreateView):
|
||||
|
||||
try:
|
||||
part = Part.objects.get(id=part_id)
|
||||
parts = form.fields['supplier_part'].queryset
|
||||
parts = parts.filter(part=part.id)
|
||||
# Hide the 'part' field (as a valid part is selected)
|
||||
form.fields['part'].widget = HiddenInput()
|
||||
|
||||
|
||||
# If the part is NOT purchaseable, hide the supplier_part field
|
||||
if not part.purchaseable:
|
||||
form.fields['supplier_part'].widget = HiddenInput()
|
||||
|
||||
form.fields['supplier_part'].queryset = parts
|
||||
else:
|
||||
# Pre-select the allowable SupplierPart options
|
||||
parts = form.fields['supplier_part'].queryset
|
||||
parts = parts.filter(part=part.id)
|
||||
|
||||
# If there is one (and only one) supplier part available, pre-select it
|
||||
all_parts = parts.all()
|
||||
if len(all_parts) == 1:
|
||||
form.fields['supplier_part'].queryset = parts
|
||||
|
||||
# TODO - This does NOT work for some reason? Ref build.views.BuildItemCreate
|
||||
form.fields['supplier_part'].initial = all_parts[0].id
|
||||
# If there is one (and only one) supplier part available, pre-select it
|
||||
all_parts = parts.all()
|
||||
if len(all_parts) == 1:
|
||||
|
||||
# TODO - This does NOT work for some reason? Ref build.views.BuildItemCreate
|
||||
form.fields['supplier_part'].initial = all_parts[0].id
|
||||
|
||||
except Part.DoesNotExist:
|
||||
pass
|
||||
|
||||
# Hide the 'part' field
|
||||
form.fields['part'].widget = HiddenInput()
|
||||
|
||||
# Otherwise if the user has selected a SupplierPart, we know what Part they meant!
|
||||
elif form['supplier_part'].value() is not None:
|
||||
pass
|
||||
|
Reference in New Issue
Block a user