update excel

This commit is contained in:
2026-01-27 14:21:46 +03:30
parent 3b4ef2c1e1
commit c55433a1b7
4 changed files with 60 additions and 9 deletions

View File

@@ -2629,9 +2629,9 @@ def all_products_transport_excel(request):
transports = transports.filter(
build_query(filterset_class.Meta.fields, search)
)
transports = transports.order_by('-date', '-create_date')
transports = transports.iterator(chunk_size=2000)
excel_options = [
'ردیف',
'کد رهگیری',
@@ -2664,7 +2664,19 @@ def all_products_transport_excel(request):
worksheet.insert_rows(1)
cell = worksheet.cell(row=1, column=1)
cell.alignment = Alignment(horizontal='center', vertical='center')
header_list2 = [
'محصول',
'تعداد بار',
'حجم بار (کیلوگرم)',
'تعداد بار داخل استان',
'حجم بار داخل استان',
'درصد بار داخل استان',
'تعداد بار خارج استان',
'حجم بار خارج استان',
'درصد بار خارج استان',
]
create_header(worksheet, header_list2, 5, 2, height=20.8, border_style='thin')
if 'date1' in request.GET:
date1 = datetime.datetime.strptime(str(request.GET['date1']), '%Y-%m-%d').date()
date2 = datetime.datetime.strptime(str(request.GET['date2']), '%Y-%m-%d').date()
@@ -2716,6 +2728,30 @@ def all_products_transport_excel(request):
l += 1
create_value(worksheet, list1, l + 1, 1)
aggregation = AllProductsTransport.objects.filter(**filters).aggregate(
total=Sum('quantity'),
input_total=Sum('quantity', filter=Q(out=False)),
output_total=Sum('quantity', filter=Q(out=True)),
input_count=Count('id', filter=Q(out=False)),
output_count=Count('id', filter=Q(out=True)),
total_count=Count('id'),
)
total_count = aggregation['total_count'] or 0
total_quantity = aggregation['total'] or 0
input_quantity = aggregation['input_total'] or 0
output_quantity = aggregation['output_total'] or 0
input_count = aggregation['input_count'] or 0
output_count = aggregation['output_count'] or 0
if total_count > 0 and (input_quantity + output_quantity) > 0:
input_percent = round((input_quantity / (input_quantity + output_quantity)) * 100, 1)
output_percent = round((output_quantity / (input_quantity + output_quantity)) * 100, 1)
else:
input_percent = 0
output_percent = 0
list2 = [
'مجموع==>',
@@ -2744,6 +2780,21 @@ def all_products_transport_excel(request):
]
create_value(worksheet, list2, l + 3, 1, color='green')
value_header_list2 = [
product_type if product_type else '-',
int(total_count),
int(total_quantity),
int(input_count),
int(input_quantity),
input_percent,
int(output_count),
int(output_quantity),
output_percent,
]
create_value(worksheet, value_header_list2, 3, 5, border_style='thin')
workbook.save(output)
output.seek(0)