add height to all excel

This commit is contained in:
7nimor
2025-08-02 08:21:04 +03:30
parent ae7bdd76ef
commit f59542252b
3 changed files with 22 additions and 31 deletions

View File

@@ -1,8 +1,5 @@
from datetime import datetime
from io import BytesIO
from django.db.models import Q
from django.http import HttpResponse
from openpyxl import Workbook
from rest_framework import viewsets
@@ -10,12 +7,7 @@ from rest_framework.decorators import action
from apps.authorization.api.v1.serializers import UserRelationSerializer
from apps.authorization.models import UserRelations
from apps.product import models as product_models
from apps.product.web.api.v1.serializers import quota_distribution_serializers as distribution_serializers
from apps.product.web.api.v1.serializers.product_serializers import IncentivePlanSerializer
from common.helper_excel import create_header, excel_description, create_header_freez, create_value, shamsi_date, \
convert_str_to_date
from common.helpers import get_organization_by_user
from common.helper_excel import excel_description, create_header_freez, create_value
class AuthExcelViewSet(viewsets.ModelViewSet):
@@ -58,7 +50,7 @@ class AuthExcelViewSet(viewsets.ModelViewSet):
excel_description(worksheet, 'B1', f'کاربران', row2='C3')
create_header_freez(worksheet, excel_options, 1, 6, 7, height=22, width=20)
create_header_freez(worksheet, excel_options, 1, 6, 7, height=25, width=20)
l = 6
m = 1
@@ -111,7 +103,7 @@ class AuthExcelViewSet(viewsets.ModelViewSet):
is_active,
fa_permission_text
]
create_value(worksheet, list1, l + 1, 1, m=m)
create_value(worksheet, list1, l + 1, 1, height=24, m=m)
m += 1
l += 1
@@ -120,10 +112,9 @@ class AuthExcelViewSet(viewsets.ModelViewSet):
output.seek(0)
response = HttpResponse(
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') # noqa
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') # noqa
response[
'Content-Disposition'] = f'attachment; filename="کاربران.xlsx"'.encode( # noqa
'Content-Disposition'] = f'attachment; filename="کاربران.xlsx"'.encode( # noqa
'utf-8')
response.write(output.getvalue())
return response

View File

@@ -43,13 +43,13 @@ class ProductExcelViewSet(viewsets.ModelViewSet):
product = product.filter(
Q(assigned_organization=organization)
).order_by('-modify_date')
description_name = 'سهمیه' # noqa
description_name = 'سهمیه' # noqa
elif query.get('param') == 'assigner':
product = product.filter(
Q(assigner_organization=organization)
).order_by('-modify_date')
description_name = 'توزیع' # noqa
description_name = 'توزیع' # noqa
elif query.get('param') == 'all':
product = product.filter(
@@ -86,11 +86,11 @@ class ProductExcelViewSet(viewsets.ModelViewSet):
]
create_header(worksheet, header_list, 5, 2, height=20, border_style='thin')
create_header(worksheet, header_list, 5, 2, height=25, border_style='thin')
excel_description(worksheet, 'B1', f'{description_name}', row2='C3')
create_header_freez(worksheet, excel_options, 1, 6, 7, height=22, width=20)
create_header_freez(worksheet, excel_options, 1, 6, 7, height=25, width=20)
l = 6
m = 1
@@ -114,7 +114,7 @@ class ProductExcelViewSet(viewsets.ModelViewSet):
data.get('warehouse_entry') or 0,
data.get('description') or '-'
]
create_value(worksheet, list1, l + 1, 1, m=m)
create_value(worksheet, list1, l + 1, 1, height=24, m=m)
m += 1
l += 1
@@ -152,15 +152,15 @@ class ProductExcelViewSet(viewsets.ModelViewSet):
'',
]
create_value(worksheet, list2, l + 3, 1, color='gray') # noqa
create_value(worksheet, list2, l + 3, 1, color='gray') # noqa
workbook.save(output)
output.seek(0)
response = HttpResponse(
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') # noqa
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') # noqa
response[
'Content-Disposition'] = f'attachment; filename="سهمیه.xlsx"'.encode( # noqa
'Content-Disposition'] = f'attachment; filename="سهمیه.xlsx"'.encode( # noqa
'utf-8')
response.write(output.getvalue())
return response
@@ -203,7 +203,7 @@ class ProductExcelViewSet(viewsets.ModelViewSet):
excel_description(worksheet, 'B1', f'طرح های تشویقی', row2='C3')
create_header_freez(worksheet, excel_options, 1, 6, 7, height=22, width=20)
create_header_freez(worksheet, excel_options, 1, 6, 7, height=25, width=20)
l = 6
m = 1
@@ -225,7 +225,7 @@ class ProductExcelViewSet(viewsets.ModelViewSet):
str(shamsi_date(convert_str_to_date(data.get('start_date_limit')), in_value=True)),
str(shamsi_date(convert_str_to_date(data.get('end_date_limit')), in_value=True)),
]
create_value(worksheet, list1, l + 1, 1, m=m)
create_value(worksheet, list1, l + 1, 1, height=24, m=m)
m += 1
l += 1
@@ -241,7 +241,7 @@ class ProductExcelViewSet(viewsets.ModelViewSet):
'',
]
create_value(worksheet, list2, l + 3, 1, color='gray') # noqa
create_value(worksheet, list2, l + 3, 1, height=24, color='gray') # noqa
workbook.save(output)
output.seek(0)
@@ -249,7 +249,7 @@ class ProductExcelViewSet(viewsets.ModelViewSet):
response = HttpResponse(
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
response[
'Content-Disposition'] = f'attachment; filename="طرح های تشویقی.xlsx"'.encode( # noqa
'Content-Disposition'] = f'attachment; filename="طرح های تشویقی.xlsx"'.encode( # noqa
'utf-8')
response.write(output.getvalue())
return response

View File

@@ -51,9 +51,9 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet):
]
create_header(worksheet, header_list, 5, 2, height=20, border_style='thin')
create_header(worksheet, header_list, 5, 2, height=25, border_style='thin')
excel_description(worksheet, 'B1', f'ورودی به انبار', row2='C3')
create_header_freez(worksheet, excel_options, 1, 6, 7, height=22, width=20)
create_header_freez(worksheet, excel_options, 1, 6, 7, height=25, width=20)
l = 6
m = 1
@@ -74,14 +74,14 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet):
str(shamsi_date(convert_str_to_date(data['create_date']), in_value=True)) if data.get(
'create_date') else '',
str(data[
'distribution'].get('distribution')) or '-',
'distribution'].get('distribution')) or '-',
data.get('weight') or 0,
data.get('lading_number') or '-',
data.get('delivery_address') or '-',
document_value,
data.get('notes') or '',
]
create_value(worksheet, list1, l + 1, 1, m=m)
create_value(worksheet, list1, l + 1, 1, height=23, m=m)
if document:
worksheet.cell(row=l + 1, column=7).font = Font(color="0563C1", underline='single', bold=True)
m += 1
@@ -105,7 +105,7 @@ class WareHouseExcelViewSet(viewsets.ModelViewSet):
'',
''
]
create_value(worksheet, list2, l + 3, 1, color='gray')
create_value(worksheet, list2, l + 3, 1, color='gray', height=23)
workbook.save(output)
output.seek(0)