From ba49b080b0154774c6543b5d0be5efa80efb253e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 28 Apr 2019 11:46:53 +1000 Subject: [PATCH 1/3] Some small tweaks --- InvenTree/part/models.py | 2 +- InvenTree/stock/models.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 4022b7ec71..887c983511 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -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) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index 636efeb293..e74c4c30d5 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -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: From a9224445b6336fe2289dada0232c7157d461069e Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 28 Apr 2019 11:49:20 +1000 Subject: [PATCH 2/3] Added docstring --- InvenTree/InvenTree/serializers.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/InvenTree/InvenTree/serializers.py b/InvenTree/InvenTree/serializers.py index 7149668cc4..4ad5d1b87a 100644 --- a/InvenTree/InvenTree/serializers.py +++ b/InvenTree/InvenTree/serializers.py @@ -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) From 2f7f49c116d3358c6756584ee31b48aa222e95bd Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 28 Apr 2019 11:54:40 +1000 Subject: [PATCH 3/3] PEP fix --- InvenTree/stock/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/InvenTree/stock/models.py b/InvenTree/stock/models.py index e74c4c30d5..2f61c068cd 100644 --- a/InvenTree/stock/models.py +++ b/InvenTree/stock/models.py @@ -84,7 +84,7 @@ class StockItem(models.Model): - 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: