fix inventory edit weight bug - fix inventory document - set new validations for distribution

This commit is contained in:
2025-08-07 16:59:17 +03:30
parent 82b1dc3637
commit 8e143a0033
4 changed files with 21 additions and 4 deletions

View File

@@ -402,7 +402,7 @@ class Quota(BaseModel):
now = datetime.now()
persian_date = jdatetime.datetime.fromgregorian(datetime=now)
return persian_date.month in self.month_choices
return persian_date.month in self.sale_license
def save(self, calculate_final_price=None, *args, **kwargs):
if not self.quota_id:

View File

@@ -1,5 +1,6 @@
from rest_framework import serializers
from apps.product import models as product_models
from rest_framework.exceptions import APIException
from apps.product.web.api.v1.serializers.quota_serializers import QuotaSerializer
from django.db import models
from apps.product.exceptions import (
@@ -55,6 +56,19 @@ class QuotaDistributionSerializer(serializers.ModelSerializer):
if total + amount > quota.quota_weight:
raise QuotaWeightException()
# total warehouse inventory entry
total_entry = self.instance.inventory_entry.aggregate(
total=models.Sum('weight')
)['total'] or 0
# if inventory entry weight is bigger than distribute weight in edit distribution
if total_entry > self.instance.weight:
raise APIException("وزن وارد شده کمتر از وزن ورودی به انبار است", code=403) # noqa
# if weight is more than distribution remaining weight
if self.instance.weight > self.instance.remaining_weight:
raise APIException("وزن وارد شده بیشتر از وزن باقیمانده است", code=403) # noqa
return data
def to_representation(self, instance):