fix - list of pricing features in quota
This commit is contained in:
@@ -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'])
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user