From 5da20dc16c00b4ebec5ee8bba699601c87fdb5b2 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 11 Nov 2025 10:08:08 +0330 Subject: [PATCH 1/5] fix - order transactions by create_date --- apps/warehouse/web/api/v1/api.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/warehouse/web/api/v1/api.py b/apps/warehouse/web/api/v1/api.py index de89046..f80f854 100644 --- a/apps/warehouse/web/api/v1/api.py +++ b/apps/warehouse/web/api/v1/api.py @@ -147,8 +147,7 @@ class InventoryQuotaSaleTransactionViewSet(BaseViewSet, SoftDeleteMixin, Dynamic list of transactions filter by: search, all, my_transactions """ - print("ssss") - queryset = self.filter_query(self.get_queryset(visibility_by_org_scope=True)) + queryset = self.filter_query(self.get_queryset(visibility_by_org_scope=True).order_by('-create_date')) # paginate & response page = self.paginate_queryset(queryset) From a36747f9f04dd2cfdd215a064cb8d2ccefd10204 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 11 Nov 2025 10:27:19 +0330 Subject: [PATCH 2/5] fix - rancher quota weight statistic / link in herds livestock gropes --- apps/herd/services/services.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/herd/services/services.py b/apps/herd/services/services.py index 8cdce45..b1630fa 100644 --- a/apps/herd/services/services.py +++ b/apps/herd/services/services.py @@ -14,9 +14,9 @@ from apps.warehouse.models import ( ) LIVESTOCK_GROPES = { - 'I': 'industrial', # صنعتی - 'V': 'rural', # روستایی - 'N': 'nomadic' # عشایری + 'industrial': 'I', # صنعتی + 'rural': 'V', # روستایی + 'nomadic': 'N' # عشایری } @@ -85,6 +85,9 @@ def rancher_quota_weight( allocations = list(quota.livestock_allocations.all().select_related('livestock_type')) # list of quota incentive plans incentive_plans = list(quota.incentive_assignments.all().select_related('livestock_type')) + # list of rancher herds + herds = rancher.herd.all() + herd_livestock_gropes = [herd.activity for herd in herds] livestock_counts_list, livestock_counts_dict = get_rancher_statistics(rancher) @@ -94,7 +97,7 @@ def rancher_quota_weight( # calculate quota base weight by livestock type & base total weight for item in allocations: # noqa if item.livestock_type: - if rancher.activity and LIVESTOCK_GROPES[rancher.activity] == item.livestock_group: + if LIVESTOCK_GROPES[item.livestock_group] in herd_livestock_gropes: animal_type_fa = item.livestock_type.name animal_type_en = item.livestock_type.en_name per_head = item.quantity_kg From 148697c59dd5b8abbf7a230e31111eac270dce91 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 11 Nov 2025 11:01:41 +0330 Subject: [PATCH 3/5] fix - change quota weight statistic by herd light/heavy vount --- apps/herd/services/services.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/herd/services/services.py b/apps/herd/services/services.py index b1630fa..cdef63c 100644 --- a/apps/herd/services/services.py +++ b/apps/herd/services/services.py @@ -54,6 +54,30 @@ def get_rancher_statistics(rancher: Rancher = None) -> typing.Any: return [{'name': key, 'value': value} for key, value in stats.items()], stats +def get_rancher_statistic_by_herd(rancher: Rancher = None) -> typing.Any: + """ get statistics of a rancher by his herds """ # noqa + + herds = rancher.herd.all() + if herds.exists(): + stats = herds.aggregate( + herd_count=Count("id", distinct=True), + light_count=Sum('light_livestock_number'), + heavy_count=Sum('heavy_livestock_number'), + sheep=Sum('light_livestock_number'), # noqa + cow=Sum('heavy_livestock_number'), + ) + else: + stats = { + 'herd_count': 0, + 'light_count': 0, + 'heavy_count': 0, + 'sheep': 0, + 'cow': 0, + } + + return [{'name': key, 'value': value} for key, value in stats.items()], stats + + def rancher_quota_weight( rancher: Rancher, inventory_entry: InventoryEntry = None, @@ -89,7 +113,7 @@ def rancher_quota_weight( herds = rancher.herd.all() herd_livestock_gropes = [herd.activity for herd in herds] - livestock_counts_list, livestock_counts_dict = get_rancher_statistics(rancher) + livestock_counts_list, livestock_counts_dict = get_rancher_statistic_by_herd(rancher) total_weight = 0 merged = {} From 4f8705b633d18318026b8b33dacdcbe887a00925 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 11 Nov 2025 11:13:12 +0330 Subject: [PATCH 4/5] fix - pos free products --- apps/product/pos/api/v1/viewsets/product_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/product/pos/api/v1/viewsets/product_api.py b/apps/product/pos/api/v1/viewsets/product_api.py index 648a9b2..763f1a0 100644 --- a/apps/product/pos/api/v1/viewsets/product_api.py +++ b/apps/product/pos/api/v1/viewsets/product_api.py @@ -106,7 +106,7 @@ class POSFreeProductsViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSear request.data.update({ 'organization': organization.id, 'device': device.id, - 'company_fee': product_models.Broker.objects.get(organization=organization).company_fee, + 'company_fee': product_models.Broker.objects.get(name='شرکت').fix_broker_price, # noqa }) serializer = product_serializers.POSFreeProductSerializer(data=request.data, context={'device': device}) From 7a24a74757f0ed071de7fd1ed65103bf08cb5838 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Tue, 11 Nov 2025 11:29:02 +0330 Subject: [PATCH 5/5] fix - pos product company fee come from Wage model in core --- apps/product/pos/api/v1/viewsets/product_api.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/product/pos/api/v1/viewsets/product_api.py b/apps/product/pos/api/v1/viewsets/product_api.py index 763f1a0..8217e0b 100644 --- a/apps/product/pos/api/v1/viewsets/product_api.py +++ b/apps/product/pos/api/v1/viewsets/product_api.py @@ -8,6 +8,7 @@ from rest_framework.response import Response from apps.core.mixins.search_mixin import DynamicSearchMixin from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin +from apps.core.models import Wage from apps.pos_device import models as pos_models from apps.pos_device.mixins.pos_device_mixin import POSDeviceMixin from apps.product import models as product_models @@ -106,7 +107,7 @@ class POSFreeProductsViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSear request.data.update({ 'organization': organization.id, 'device': device.id, - 'company_fee': product_models.Broker.objects.get(name='شرکت').fix_broker_price, # noqa + 'company_fee': Wage.get(key='MNPC'), # noqa }) serializer = product_serializers.POSFreeProductSerializer(data=request.data, context={'device': device})