From 3cb5766961e819897a5c9e5d36392cc93cfc9bcf Mon Sep 17 00:00:00 2001 From: 7nimor <7nimor@gmail.com> Date: Tue, 16 Dec 2025 15:21:59 +0330 Subject: [PATCH 1/3] update excel --- .idea/Rasaddam_Backend.iml | 2 +- .idea/misc.xml | 2 +- .../services/excel/excel_processing.py | 37 +++++++++++++++++-- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/.idea/Rasaddam_Backend.iml b/.idea/Rasaddam_Backend.iml index 168bde0..9e31677 100644 --- a/.idea/Rasaddam_Backend.iml +++ b/.idea/Rasaddam_Backend.iml @@ -14,7 +14,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index f1b70db..e547571 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,5 +3,5 @@ - + \ No newline at end of file diff --git a/apps/warehouse/services/excel/excel_processing.py b/apps/warehouse/services/excel/excel_processing.py index bfec039..b8e2a28 100644 --- a/apps/warehouse/services/excel/excel_processing.py +++ b/apps/warehouse/services/excel/excel_processing.py @@ -248,13 +248,16 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): excel_options = [ "ردیف", "تعاونی دامدار", - "کد ملی دامدار", + "شهر تعاونی", "نام و نام خانوادگی دامدار", + "کد ملی دامدار", + "شهر دامدار", "تاریخ", "محصولات", "شناسه تراکنش", "شماره کارت", "مبلغ", + "ماهیت وزن", "وضعیت", ] # اضافه کردن ستون‌های داینامیک سهم‌ها @@ -296,7 +299,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): m = 1 # دیکشنری برای نگهداری جمع سهم‌ها share_column_totals = {name: 0 for name in share_names} - + all_weight = 0 if ser_data: for data in ser_data: items = data.get('items', []) @@ -308,11 +311,13 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): products_str = '، '.join(products_list) if products_list else '-' rancher_data = data.get('rancher') + rancher_city = rancher_data.get('city', '-') if rancher_data else '-' national_code = rancher_data.get('national_code', '-') 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 '-' + org_city = seller_org.get('city', '-') if seller_org else '-' status = TRANSACTION_STATUS_MAP.get(data.get('transaction_status'), '-') @@ -326,18 +331,41 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): ) share_values.append(share_value) share_column_totals[share_name] += share_value + items = data.get('items', []) + quota_sale_units = [ + item.get('quota_sale_unit') + for item in items + if item.get('quota_sale_unit') + ] + + # جمع وزن کل + total_weight = sum(item.get('weight', 0) for item in items) + all_weight += total_weight + # تعیین ماهیت وزن + if quota_sale_units: + all_equal = ( + len(items) > 0 and len(quota_sale_units) == len(items) and len(set(quota_sale_units)) == 1) + if all_equal: + weight_nature = f"{total_weight:,} {quota_sale_units[0] or ''}" + else: + weight_nature = "ترکیبی" + else: + weight_nature = "{0} کیلوگرم".format(total_weight) list1 = [ m, org_name, - national_code, + org_city, rancher_name, + national_code, + rancher_city, str(shamsi_date(convert_str_to_date(data['transaction_date']), in_value=True)) if data.get( 'transaction_date') else '', products_str, data.get('transaction_id') or '-', data.get('payer_cart') or '-', data.get('price_paid') or 0, + weight_nature, status, ] # اضافه کردن مقادیر سهم‌ها @@ -368,7 +396,10 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): '', '', '', + '', + '', total_price, + all_weight, '', ] # اضافه کردن جمع سهم‌ها به ردیف مجموع From feeb3f3da1731cd1e1088810a46ef5d94a69f6df Mon Sep 17 00:00:00 2001 From: 7nimor <7nimor@gmail.com> Date: Tue, 16 Dec 2025 15:22:49 +0330 Subject: [PATCH 2/3] update excel --- apps/warehouse/services/excel/excel_processing.py | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/apps/warehouse/services/excel/excel_processing.py b/apps/warehouse/services/excel/excel_processing.py index b8e2a28..4b7319d 100644 --- a/apps/warehouse/services/excel/excel_processing.py +++ b/apps/warehouse/services/excel/excel_processing.py @@ -236,12 +236,10 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): ser_data = warehouse_serializers.InventoryQuotaSaleTransactionSerializer(queryset, many=True).data - # جمع‌آوری تمام آیتم‌ها برای پیدا کردن سهم‌های یونیک all_items = [] for data in ser_data: all_items.extend(data.get('items', [])) - # محاسبه سهم‌های یونیک (برای ستون‌های داینامیک) all_share_totals = calculate_share_totals(all_items) share_names = [share['name'] for share in all_share_totals] @@ -260,23 +258,19 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): "ماهیت وزن", "وضعیت", ] - # اضافه کردن ستون‌های داینامیک سهم‌ها excel_options.extend(share_names) header_list = [ "مبلغ کل", "تعداد تراکنش‌ها", ] - # اضافه کردن سهم‌ها به هدر header_list.extend(share_names) - # محاسبه height داینامیک بر اساس تعداد آیتم‌ها header_height = max(25, 15 + len(header_list) * 3) options_height = max(25, 15 + len(excel_options) * 2) create_header(worksheet, header_list, 5, 2, height=header_height, border_style='thin') - # ساخت عنوان با بازه تاریخ start_date = request.query_params.get('start') end_date = request.query_params.get('end') @@ -297,7 +291,6 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): l = 6 m = 1 - # دیکشنری برای نگهداری جمع سهم‌ها share_column_totals = {name: 0 for name in share_names} all_weight = 0 if ser_data: @@ -321,7 +314,6 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): status = TRANSACTION_STATUS_MAP.get(data.get('transaction_status'), '-') - # محاسبه سهم‌های این تراکنش transaction_shares = calculate_share_totals(items) share_values = [] for share_name in share_names: @@ -339,10 +331,8 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): if item.get('quota_sale_unit') ] - # جمع وزن کل total_weight = sum(item.get('weight', 0) for item in items) all_weight += total_weight - # تعیین ماهیت وزن if quota_sale_units: all_equal = ( len(items) > 0 and len(quota_sale_units) == len(items) and len(set(quota_sale_units)) == 1) @@ -368,7 +358,6 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): weight_nature, status, ] - # اضافه کردن مقادیر سهم‌ها list1.extend(share_values) create_value(worksheet, list1, l + 1, 1, height=23, m=m) @@ -382,7 +371,6 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): total_price, transaction_count, ] - # اضافه کردن جمع سهم‌ها به مقادیر هدر value_list.extend([share_column_totals[name] for name in share_names]) create_value(worksheet, value_list, 3, 5, border_style='thin') @@ -402,7 +390,6 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): all_weight, '', ] - # اضافه کردن جمع سهم‌ها به ردیف مجموع list2.extend([share_column_totals[name] for name in share_names]) create_value(worksheet, list2, l + 3, 1, color='gray', height=23) From 959e9f9fe98d24664f2bebeab992594a21bd8ac2 Mon Sep 17 00:00:00 2001 From: 7nimor <7nimor@gmail.com> Date: Tue, 16 Dec 2025 15:25:59 +0330 Subject: [PATCH 3/3] 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 4b7319d..500f6e7 100644 --- a/apps/warehouse/services/excel/excel_processing.py +++ b/apps/warehouse/services/excel/excel_processing.py @@ -341,7 +341,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin): else: weight_nature = "ترکیبی" else: - weight_nature = "{0} کیلوگرم".format(total_weight) + weight_nature = f"{total_weight:,} کیلوگرم" list1 = [ m, org_name,