From ecb10496811b7f032d4cf534fe94f3ce7f36f108 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Mon, 22 Sep 2025 15:22:04 +0330 Subject: [PATCH] change map structure of rancher statistics --- apps/herd/services/services.py | 6 +++--- .../api/v1/serializers/quota_distribution_serializers.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/herd/services/services.py b/apps/herd/services/services.py index 184d74a..c66e61a 100644 --- a/apps/herd/services/services.py +++ b/apps/herd/services/services.py @@ -22,7 +22,7 @@ def get_rancher_statistics(rancher: Rancher = None) -> typing.Any: camel_count=Count('id', filter=Q(type__name='شتر')), horse_count=Count('id', filter=Q(type__name='بز')), ) - return stats + return [{'name': key, 'value': value} for key, value in stats.items()], stats def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distribution: QuotaDistribution = None): @@ -53,7 +53,7 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distri # list of quota incentive plans incentive_plans = list(quota.incentive_assignments.all().select_related('livestock_type')) - livestock_counts = get_rancher_statistics(rancher) + livestock_counts_list, livestock_counts_dict = get_rancher_statistics(rancher) total_weight = 0 merged = {} @@ -62,7 +62,7 @@ def rancher_quota_weight(rancher, inventory_entry: InventoryEntry = None, distri if item.livestock_type: animal_type = item.livestock_type.name per_head = item.quantity_kg - count = livestock_counts.get(live_stock_meta.get(animal_type), 0) + count = livestock_counts_dict.get(live_stock_meta.get(animal_type), 0) weight = per_head * count total_weight += weight diff --git a/apps/product/pos/api/v1/serializers/quota_distribution_serializers.py b/apps/product/pos/api/v1/serializers/quota_distribution_serializers.py index 4789201..dd95198 100644 --- a/apps/product/pos/api/v1/serializers/quota_distribution_serializers.py +++ b/apps/product/pos/api/v1/serializers/quota_distribution_serializers.py @@ -127,7 +127,8 @@ class QuotaDistributionSerializer(serializers.ModelSerializer): if 'rancher' in self.context.keys(): # rancher herd & live stock statistics - representation['rancher_statistics'] = get_rancher_statistics(self.context['rancher']) + livestock_counts_list, livestock_counts_dict = get_rancher_statistics(self.context['rancher']) + representation['rancher_statistics'] = livestock_counts_list # rancher live stock statistics by quota distributions representation['rancher_quota_weight_statistics'] = rancher_quota_weight(