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'] or 0
|
||||
org_quota_stat.remaining_amount = org_quota_stat.total_amount - org_quota_stat.total_distributed
|
||||
if org_quota_stat.remaining_amount < 0:
|
||||
raise QuotaException(
|
||||
"وزن سهمیه نباید از مقدار توزیع شده کمتر باشد", # noqa
|
||||
status.HTTP_403_FORBIDDEN
|
||||
)
|
||||
QuotaStatsValidator.validate_quota_weight_update(org_quota_stat.remaining_amount)
|
||||
org_quota_stat.save(update_fields=['total_amount', 'total_distributed', 'sold_amount', 'remaining_amount'])
|
||||
|
||||
# delete quota
|
||||
|
||||
@@ -2,7 +2,7 @@ from django.apps import apps
|
||||
from django.core.exceptions import ValidationError
|
||||
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):
|
||||
@@ -19,6 +19,14 @@ class QuotaStatsValidator:
|
||||
organization_quota_stats = get_model("product", "OrganizationQuotaStats")
|
||||
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
|
||||
def validate_assigner_has_enough(assigner_org, quota, amount, allow_zero=False, update_operation=None):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user