add: add save method to Inventory model
This commit is contained in:
@@ -31,6 +31,11 @@ class Inventory(BaseModel):
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.product} in {self.wherehouse}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if self.quantity == 0:
|
||||
self.is_invalid = True
|
||||
return super().save()
|
||||
|
||||
class Meta:
|
||||
verbose_name = _('inventar')
|
||||
|
||||
@@ -52,7 +52,6 @@ class InvalidProductCreateSerializer(serializers.Serializer):
|
||||
wherehouse=validated_data.get('inventory').wherehouse
|
||||
)
|
||||
invalid_product.witnesses.set(witnesses_ids)
|
||||
invalid_product.inventory.is_invalid = True
|
||||
invalid_product.inventory.quantity -= validated_data.get('amount')
|
||||
invalid_product.inventory.save()
|
||||
invalid_product.save()
|
||||
|
||||
Reference in New Issue
Block a user