From 012a4240f1508a339a6db3aba2553b0c82b52508 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 2 Dec 2025 14:39:42 +0330 Subject: [PATCH] fix - list of pricing features in quota --- apps/product/models.py | 18 ++++++++++++++++++ .../api/v1/serializers/quota_serializers.py | 7 +++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/apps/product/models.py b/apps/product/models.py index 2bfd223..ce9d209 100644 --- a/apps/product/models.py +++ b/apps/product/models.py @@ -529,6 +529,24 @@ class Quota(BaseModel): "inventory_entry_balance": stat.first().inventory_entry_balance if stat.exists() else 0, } + def get_quota_stat(self, org: Organization): + """ + get stats of quota from org quota stat model + """ + + stat = OrganizationQuotaStats.objects.filter( + quota=self, + organization=org + ) + + if not stat.exists() and org.type.key == 'ADM': + # if org is admin just see the quota was created by registerer org + org = self.registerer_organization + stat = OrganizationQuotaStats.objects.filter( + quota=self, + ) + return stat.first() + def soft_delete(self): self.trash = True self.save(update_fields=['trash']) diff --git a/apps/product/web/api/v1/serializers/quota_serializers.py b/apps/product/web/api/v1/serializers/quota_serializers.py index 8e2b814..565b82c 100644 --- a/apps/product/web/api/v1/serializers/quota_serializers.py +++ b/apps/product/web/api/v1/serializers/quota_serializers.py @@ -89,13 +89,16 @@ class QuotaSerializer(serializers.ModelSerializer): representation['incentive_plan'] = list(incentive_plan_map.values()) + # get quota stat for filtering pricing features (every distribution of this quota has different attributes) + quota_stat = instance.get_quota_stat(org) if instance.edited_pricing_features else None # noqa + representation['attribute_values'] = product_serializers.AttributeValueSerializer( - instance.attribute_values.all(), + instance.attribute_values.filter(org_quota_stat=quota_stat), many=True ).data representation['brokers'] = QuotaBrokerValueSerializer( - instance.broker_values.all(), + instance.broker_values.filter(org_quota_stat=quota_stat), many=True ).data