fix - set exception for quota stats update
This commit is contained in:
@@ -328,11 +328,7 @@ def organization_quota_stats(sender, instance: Quota, created: bool, **kwargs):
|
|||||||
total=Sum('weight')
|
total=Sum('weight')
|
||||||
)['total'] or 0
|
)['total'] or 0
|
||||||
org_quota_stat.remaining_amount = org_quota_stat.total_amount - org_quota_stat.total_distributed
|
org_quota_stat.remaining_amount = org_quota_stat.total_amount - org_quota_stat.total_distributed
|
||||||
if org_quota_stat.remaining_amount < 0:
|
QuotaStatsValidator.validate_quota_weight_update(org_quota_stat.remaining_amount)
|
||||||
raise QuotaException(
|
|
||||||
"وزن سهمیه نباید از مقدار توزیع شده کمتر باشد", # noqa
|
|
||||||
status.HTTP_403_FORBIDDEN
|
|
||||||
)
|
|
||||||
org_quota_stat.save(update_fields=['total_amount', 'total_distributed', 'sold_amount', 'remaining_amount'])
|
org_quota_stat.save(update_fields=['total_amount', 'total_distributed', 'sold_amount', 'remaining_amount'])
|
||||||
|
|
||||||
# delete quota
|
# delete quota
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from django.apps import apps
|
|||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
|
|
||||||
from apps.product.exceptions import DistributionException
|
from apps.product.exceptions import DistributionException, QuotaException
|
||||||
|
|
||||||
|
|
||||||
def get_model(app_label, model_name):
|
def get_model(app_label, model_name):
|
||||||
@@ -19,6 +19,14 @@ class QuotaStatsValidator:
|
|||||||
organization_quota_stats = get_model("product", "OrganizationQuotaStats")
|
organization_quota_stats = get_model("product", "OrganizationQuotaStats")
|
||||||
return organization_quota_stats.objects.filter(quota=quota, organization=organization).first() # noqa
|
return organization_quota_stats.objects.filter(quota=quota, organization=organization).first() # noqa
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def validate_quota_weight_update(remaining_amount):
|
||||||
|
if remaining_amount < 0:
|
||||||
|
raise QuotaException(
|
||||||
|
"وزن سهمیه نباید از مقدار توزیع شده کمتر باشد", # noqa
|
||||||
|
status.HTTP_403_FORBIDDEN
|
||||||
|
)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def validate_assigner_has_enough(assigner_org, quota, amount, allow_zero=False, update_operation=None):
|
def validate_assigner_has_enough(assigner_org, quota, amount, allow_zero=False, update_operation=None):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user