fix bug of inventory entry - fix weight of quotas

This commit is contained in:
2025-08-09 16:15:37 +03:30
parent 365362b739
commit 92a5d3a2eb
10 changed files with 181 additions and 32 deletions

View File

@@ -42,12 +42,19 @@ class InventoryEntrySerializer(serializers.ModelSerializer):
total=models.Sum('weight')
)['total'] or 0
if self.instance.weight is 0:
# if instance exists, for update check weight with distribution weight
if self.instance:
if self.instance.weight is 0:
if total_entered + attrs['weight'] > distribution.weight:
raise InventoryEntryWeightException()
elif self.instance.weight is not 0:
if total_entered - self.instance.weight + attrs['weight'] > distribution.weight:
raise InventoryEntryWeightException()
# if instance is not exists for create, check entry weight with distribution
elif not self.instance:
if total_entered + attrs['weight'] > distribution.weight:
raise InventoryEntryWeightException()
elif self.instance.weight is not 0:
if total_entered - self.instance.weight + attrs['weight'] > distribution.weight:
raise InventoryEntryWeightException()
return attrs