add: add save method to Inventory model
This commit is contained in:
@@ -32,6 +32,11 @@ class Inventory(BaseModel):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f'{self.product} in {self.wherehouse}'
|
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:
|
class Meta:
|
||||||
verbose_name = _('inventar')
|
verbose_name = _('inventar')
|
||||||
verbose_name_plural = _("inventarlar")
|
verbose_name_plural = _("inventarlar")
|
||||||
|
|||||||
@@ -52,7 +52,6 @@ class InvalidProductCreateSerializer(serializers.Serializer):
|
|||||||
wherehouse=validated_data.get('inventory').wherehouse
|
wherehouse=validated_data.get('inventory').wherehouse
|
||||||
)
|
)
|
||||||
invalid_product.witnesses.set(witnesses_ids)
|
invalid_product.witnesses.set(witnesses_ids)
|
||||||
invalid_product.inventory.is_invalid = True
|
|
||||||
invalid_product.inventory.quantity -= validated_data.get('amount')
|
invalid_product.inventory.quantity -= validated_data.get('amount')
|
||||||
invalid_product.inventory.save()
|
invalid_product.inventory.save()
|
||||||
invalid_product.save()
|
invalid_product.save()
|
||||||
|
|||||||
Reference in New Issue
Block a user