Fixed stock import as it was not validating the serial properly (#1559)

This commit is contained in:
Francois 2021-05-06 16:57:16 -05:00 committed by GitHub
parent 3a1c233bff
commit 5ed17022f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -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)

View File

@ -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'),