From fae6fea2fa7f65aa2ff09da475d4c3257e8143cc Mon Sep 17 00:00:00 2001 From: 7nimor <7nimor@gmail.com> Date: Sun, 14 Dec 2025 14:06:49 +0330 Subject: [PATCH 1/5] update excel --- apps/warehouse/services/excel/excel_processing.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/warehouse/services/excel/excel_processing.py b/apps/warehouse/services/excel/excel_processing.py index c2d735d..01e9e29 100644 --- a/apps/warehouse/services/excel/excel_processing.py +++ b/apps/warehouse/services/excel/excel_processing.py @@ -249,6 +249,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): "ردیف", "تعاونی دامدار", "کد ملی دامدار", + "نام و نام خانوادگی دامدار", "تاریخ", "محصولات", "شناسه تراکنش", @@ -308,6 +309,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): rancher_data = data.get('rancher') national_code = rancher_data.get('national_code', '-') if rancher_data else '-' + rancher_name = rancher_data.get('fullname', '-') if rancher_data else '-' seller_org = data.get('seller_organization') org_name = seller_org.get('name', '-') if seller_org else '-' @@ -329,6 +331,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): m, org_name, national_code, + rancher_name, str(shamsi_date(convert_str_to_date(data['transaction_date']), in_value=True)) if data.get( 'transaction_date') else '', products_str, @@ -364,6 +367,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): '', '', '', + '', total_price, '', ] From 3767bf0032e38de36b6a54238569d89747f076fe Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sun, 14 Dec 2025 14:07:46 +0330 Subject: [PATCH 2/5] import - ranchers dashboard --- .../services/rancher_dashboard_service.py | 47 +++++++++++++++++-- apps/herd/web/api/v1/api.py | 22 +++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/apps/herd/services/rancher_dashboard_service.py b/apps/herd/services/rancher_dashboard_service.py index 6991c6c..8871278 100644 --- a/apps/herd/services/rancher_dashboard_service.py +++ b/apps/herd/services/rancher_dashboard_service.py @@ -2,6 +2,7 @@ from django.db.models import Sum, Count, Q from django.db.models.functions import Coalesce from apps.herd.models import Rancher, Herd +from apps.warehouse.models import InventoryQuotaSaleItem class RancherDashboardService: @@ -28,9 +29,9 @@ class RancherDashboardService: total_without_herd=Coalesce(Count("id", filter=Q(without_herd=True)), 0), total_natural_ranchers=Coalesce(Count("id", filter=Q(rancher_type='N')), 0), total_legal_ranchers=Coalesce(Count("id", filter=Q(rancher_type='L')), 0), - total_industrial_ranchers=Coalesce(Count("id", filter=Q(rancher_type='I')), 0), - total_village_ranchers=Coalesce(Count("id", filter=Q(rancher_type='V')), 0), - total_nomadic_ranchers=Coalesce(Count("id", filter=Q(rancher_type='N')), 0), + total_industrial_ranchers=Coalesce(Count("id", filter=Q(activity='I')), 0), + total_village_ranchers=Coalesce(Count("id", filter=Q(activity='V')), 0), + total_nomadic_ranchers=Coalesce(Count("id", filter=Q(activity='N')), 0), ) herds_data = herds.aggregate( @@ -43,3 +44,43 @@ class RancherDashboardService: ) return {"rancher_dashboard": ranchers_data, "herd_dashboard": herds_data} + + @staticmethod + def get_rancher_dashboard(self, rancher: Rancher): + """ + get rancher dashboard + """ + + rancher_data = rancher.herd.aggregate( + total_herds_count=Coalesce(Count("id"), 0), + total_heavy_livestock_count=Coalesce(Sum("heavy_livestock_number"), 0), + total_light_livestock_count=Coalesce(Sum("light_livestock_number"), 0), + ) + + transaction_sale_items = InventoryQuotaSaleItem.objects.select_related( + 'transaction', 'quota_stat' + ).filter( + transaction__rancher=rancher, + # transaction__transaction_status='success', + ).aggregate( + total_purchased_weight=Coalesce(Sum('weight'), 0), + ) + + rancher_data.update(transaction_sale_items) + + return rancher_data + + @staticmethod + def rancher_dashboard_by_quota_usage(self, rancher: Rancher): + """ + get rancher dashboard by quota usage + """ + + transaction_sale_items = InventoryQuotaSaleItem.objects.select_related( + 'transaction', 'quota_stat' + ).filter( + transaction__rancher=rancher, + transaction__transaction_status='success', + ) + + return diff --git a/apps/herd/web/api/v1/api.py b/apps/herd/web/api/v1/api.py index b18bb2f..a7dcf14 100644 --- a/apps/herd/web/api/v1/api.py +++ b/apps/herd/web/api/v1/api.py @@ -195,3 +195,25 @@ class RancherViewSet(BaseViewSet, RancherDashboardService, SoftDeleteMixin, view query_string=query_string, ) return Response(rancher_dashboard_data) + + @action( + methods=['get'], + detail=True, + url_path='rancher_dashboard', + url_name='rancher_dashboard', + name='rancher_dashboard' + ) + def rancher_dashboard(self, request, pk=None): + """ rancher dashboard """ + + rancher = self.get_object() + + query_param = self.request.query_params # noqa + + query_string = query_param.get('search', None) + + rancher_dashboard_data = self.get_rancher_dashboard( + self, + rancher=rancher + ) + return Response(rancher_dashboard_data) From 99382817c1933cf8dcfbb4b61299a798d7991c70 Mon Sep 17 00:00:00 2001 From: 7nimor <7nimor@gmail.com> Date: Sun, 14 Dec 2025 14:11:53 +0330 Subject: [PATCH 3/5] update excel --- apps/warehouse/services/excel/excel_processing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/warehouse/services/excel/excel_processing.py b/apps/warehouse/services/excel/excel_processing.py index 01e9e29..89e591c 100644 --- a/apps/warehouse/services/excel/excel_processing.py +++ b/apps/warehouse/services/excel/excel_processing.py @@ -309,7 +309,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): rancher_data = data.get('rancher') national_code = rancher_data.get('national_code', '-') if rancher_data else '-' - rancher_name = rancher_data.get('fullname', '-') if rancher_data else '-' + rancher_name = data.get('rancher_fullname', '-') if rancher_data else '-' seller_org = data.get('seller_organization') org_name = seller_org.get('name', '-') if seller_org else '-' From 8c93de1ec008aa3516b0909ce25f5ee46a517173 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sun, 14 Dec 2025 14:17:22 +0330 Subject: [PATCH 4/5] ffff --- apps/herd/services/rancher_dashboard_service.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/herd/services/rancher_dashboard_service.py b/apps/herd/services/rancher_dashboard_service.py index 8871278..9937542 100644 --- a/apps/herd/services/rancher_dashboard_service.py +++ b/apps/herd/services/rancher_dashboard_service.py @@ -81,6 +81,6 @@ class RancherDashboardService: ).filter( transaction__rancher=rancher, transaction__transaction_status='success', - ) + ).values('quota_stat') return From 3eb898a48186e7a3cc6fcd85902d365a2a0b0f80 Mon Sep 17 00:00:00 2001 From: Mojtaba-z Date: Sun, 14 Dec 2025 14:21:17 +0330 Subject: [PATCH 5/5] import - rancher dashboard by quota usage --- .../services/rancher_dashboard_service.py | 6 +++-- apps/herd/web/api/v1/api.py | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/apps/herd/services/rancher_dashboard_service.py b/apps/herd/services/rancher_dashboard_service.py index 9937542..ae440d0 100644 --- a/apps/herd/services/rancher_dashboard_service.py +++ b/apps/herd/services/rancher_dashboard_service.py @@ -71,7 +71,7 @@ class RancherDashboardService: return rancher_data @staticmethod - def rancher_dashboard_by_quota_usage(self, rancher: Rancher): + def get_rancher_dashboard_by_quota_usage(self, rancher: Rancher): """ get rancher dashboard by quota usage """ @@ -83,4 +83,6 @@ class RancherDashboardService: transaction__transaction_status='success', ).values('quota_stat') - return + print(list(set(transaction_sale_items))) + + return {} diff --git a/apps/herd/web/api/v1/api.py b/apps/herd/web/api/v1/api.py index a7dcf14..c950a2c 100644 --- a/apps/herd/web/api/v1/api.py +++ b/apps/herd/web/api/v1/api.py @@ -217,3 +217,25 @@ class RancherViewSet(BaseViewSet, RancherDashboardService, SoftDeleteMixin, view rancher=rancher ) return Response(rancher_dashboard_data) + + @action( + methods=['get'], + detail=True, + url_path='rancher_dashboard_by_quota_usage', + url_name='rancher_dashboard_by_quota_usage', + name='rancher_dashboard_by_quota_usage' + ) + def rancher_dashboard_by_quota_usage(self, request, pk=None): + """ rancher dashboard """ + + rancher = self.get_object() + + query_param = self.request.query_params # noqa + + query_string = query_param.get('search', None) + + rancher_dashboard_data = self.get_rancher_dashboard_by_quota_usage( + self, + rancher=rancher + ) + return Response(rancher_dashboard_data)