mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fixed stock import as it was not validating the serial properly (#1559)
This commit is contained in:
parent
3a1c233bff
commit
5ed17022f2
@ -56,7 +56,7 @@ class LocationAdmin(ImportExportModelAdmin):
|
|||||||
class StockItemResource(ModelResource):
|
class StockItemResource(ModelResource):
|
||||||
""" Class for managing StockItem data import/export """
|
""" Class for managing StockItem data import/export """
|
||||||
|
|
||||||
# Custom manaegrs for ForeignKey fields
|
# Custom managers for ForeignKey fields
|
||||||
part = Field(attribute='part', widget=widgets.ForeignKeyWidget(Part))
|
part = Field(attribute='part', widget=widgets.ForeignKeyWidget(Part))
|
||||||
|
|
||||||
part_name = Field(attribute='part__full_name', readonly=True)
|
part_name = Field(attribute='part__full_name', readonly=True)
|
||||||
|
@ -228,7 +228,7 @@ class StockItem(MPTTModel):
|
|||||||
super(StockItem, self).validate_unique(exclude)
|
super(StockItem, self).validate_unique(exclude)
|
||||||
|
|
||||||
# If the serial number is set, make sure it is not a duplicate
|
# If the serial number is set, make sure it is not a duplicate
|
||||||
if self.serial is not None:
|
if self.serial:
|
||||||
# Query to look for duplicate serial numbers
|
# Query to look for duplicate serial numbers
|
||||||
parts = PartModels.Part.objects.filter(tree_id=self.part.tree_id)
|
parts = PartModels.Part.objects.filter(tree_id=self.part.tree_id)
|
||||||
stock = StockItem.objects.filter(part__in=parts, serial=self.serial)
|
stock = StockItem.objects.filter(part__in=parts, serial=self.serial)
|
||||||
@ -281,7 +281,7 @@ class StockItem(MPTTModel):
|
|||||||
|
|
||||||
if self.part is not None:
|
if self.part is not None:
|
||||||
# A part with a serial number MUST have the quantity set to 1
|
# A part with a serial number MUST have the quantity set to 1
|
||||||
if self.serial is not None:
|
if self.serial:
|
||||||
if self.quantity > 1:
|
if self.quantity > 1:
|
||||||
raise ValidationError({
|
raise ValidationError({
|
||||||
'quantity': _('Quantity must be 1 for item with a serial number'),
|
'quantity': _('Quantity must be 1 for item with a serial number'),
|
||||||
|
Loading…
Reference in New Issue
Block a user