mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
commit
77f4717479
@ -37,6 +37,11 @@ class InvenTreeModelSerializer(serializers.ModelSerializer):
|
||||
"""
|
||||
|
||||
def validate(self, data):
|
||||
""" Perform serializer validation.
|
||||
In addition to running validators on the serializer fields,
|
||||
this class ensures that the underlying model is also validated.
|
||||
"""
|
||||
|
||||
# Run any native validation checks first (may throw an ValidationError)
|
||||
data = super(serializers.ModelSerializer, self).validate(data)
|
||||
|
||||
|
@ -533,7 +533,7 @@ class SupplierPart(models.Model):
|
||||
return cost + self.base_cost
|
||||
|
||||
def __str__(self):
|
||||
return "{sku} - {supplier}".format(
|
||||
return "{supplier} ({sku})".format(
|
||||
sku=self.SKU,
|
||||
supplier=self.supplier.name)
|
||||
|
||||
|
@ -77,6 +77,14 @@ class StockItem(models.Model):
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
""" Validate the StockItem object (separate to field validation)
|
||||
|
||||
The following validation checks are performed:
|
||||
|
||||
- The 'part' and 'supplier_part.part' fields cannot point to the same Part object
|
||||
- The 'part' does not belong to itself
|
||||
- Quantity must be 1 if the StockItem has a serial number
|
||||
"""
|
||||
|
||||
# The 'supplier_part' field must point to the same part!
|
||||
try:
|
||||
|
Loading…
Reference in New Issue
Block a user