add: add save method to Inventory model

This commit is contained in:
behruz-dev
2025-08-28 09:48:50 +05:00
parent 7dc1dc1834
commit 447e235ade
2 changed files with 5 additions and 1 deletions

View File

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

View File

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