update excel
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user