fix - excel search fields

This commit is contained in:
2025-12-02 16:32:19 +03:30
parent eb271d736f
commit 887838c0a2

View File

@@ -32,7 +32,7 @@ def process_shares(shares):
# پیدا کردن سهم‌های حساب اصلی
main_account_shares = [
share for share in processed_shares
share for share in processed_shares
if share.get('name') == 'حساب اصلی'
]
@@ -199,14 +199,22 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
name='inventory_sale_transaction_excel'
)
def inventory_sale_transaction_excel(self, request):
self.search_fields = [
'rancher_fullname', 'rancher_mobile', 'pos_device__device_identity',
'pos_device__acceptor', 'pos_device__terminal', 'pos_device__serial',
'transaction_id', 'seller_organization__name',
'quota_distribution__distribution_id', 'weight', 'delivery_address', 'transaction_price',
'price_paid', 'price_type', 'product_type', 'transactions_number', 'transaction_status',
'transaction_status_code', 'ref_num', 'terminal', 'payer_cart', 'transaction_date',
]
output = BytesIO()
workbook = Workbook()
worksheet = workbook.active
worksheet.sheet_view.rightToLeft = True
worksheet.insert_rows(1)
queryset = warehouse_models.InventoryQuotaSaleTransaction.objects.all()
if 'status' in request.GET.keys():
status_param = self.request.query_params.get('status') # noqa
@@ -229,7 +237,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
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,11 +268,11 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
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')
title = 'تراکنش‌ها'
if start_date and end_date:
start_shamsi = shamsi_date(convert_str_to_date(start_date))
@@ -276,7 +284,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
elif end_date:
end_shamsi = shamsi_date(convert_str_to_date(end_date))
title = f'تراکنش‌ها تا {end_shamsi}'
excel_description(worksheet, 'B1', title, row2='C3')
create_header_freez(worksheet, excel_options, 1, 6, 7, height=options_height, width=20)
@@ -284,7 +292,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
m = 1
# دیکشنری برای نگهداری جمع سهم‌ها
share_column_totals = {name: 0 for name in share_names}
if ser_data:
for data in ser_data:
items = data.get('items', [])
@@ -328,7 +336,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
]
# اضافه کردن مقادیر سهم‌ها
list1.extend(share_values)
create_value(worksheet, list1, l + 1, 1, height=23, m=m)
m += 1
l += 1
@@ -358,7 +366,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet, ExcelDynamicSearchMixin):
]
# اضافه کردن جمع سهم‌ها به ردیف مجموع
list2.extend([share_column_totals[name] for name in share_names])
create_value(worksheet, list2, l + 3, 1, color='gray', height=23)
workbook.save(output)
output.seek(0)