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] 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, '', ] # اضافه کردن جمع سهم‌ها به ردیف مجموع