86 lines
2.4 KiB
Python
86 lines
2.4 KiB
Python
from io import BytesIO
|
|
|
|
from django.http import HttpResponse
|
|
from django.views.decorators.csrf import csrf_exempt
|
|
from openpyxl import Workbook
|
|
from openpyxl.styles import Alignment
|
|
from rest_framework import viewsets
|
|
from rest_framework.decorators import action, api_view, permission_classes
|
|
from rest_framework.permissions import AllowAny , IsAuthenticated
|
|
|
|
from apps.warehouse import models as warehouse_models
|
|
from apps.warehouse.web.api.v1 import serializers as warehouse_serializers
|
|
from common.helper_excel import create_header, excel_description, create_header_freez, create_value
|
|
|
|
|
|
@api_view(["GET"])
|
|
@permission_classes([IsAuthenticated])
|
|
@csrf_exempt
|
|
def warehouse_excel(request):
|
|
|
|
excel_options = [
|
|
'ردیف',
|
|
'وضعیت',
|
|
'ثبت کننده',
|
|
'تاریخ ثبت',
|
|
'مرغدار',
|
|
'کشتارگاه',
|
|
'حجم',
|
|
'حجم کم شده از سالن مرغدار',
|
|
'وزن تقریبی کشتار(کیلوگرم)',
|
|
'حجم سفارشات دریافتی توسط کشتارگاه',
|
|
'اختلاف کشتار(حجم)',
|
|
|
|
]
|
|
|
|
|
|
output = BytesIO()
|
|
workbook = Workbook()
|
|
worksheet = workbook.active
|
|
worksheet.sheet_view.rightToLeft = True
|
|
worksheet.insert_rows(1)
|
|
cell = worksheet.cell(row=1, column=1)
|
|
cell.alignment = Alignment(horizontal='center', vertical='center')
|
|
|
|
header_list = [
|
|
'حجم',
|
|
'حجم کم شده از سالن مرغدار',
|
|
'وزن تقریبی کشتار(کیلوگرم)',
|
|
'حجم سفارشات دریافتی توسط کشتارگاه',
|
|
'اختلاف کشتار(حجم)',
|
|
|
|
]
|
|
|
|
create_header(worksheet, header_list, 5, 2, height=20)
|
|
|
|
excel_description(worksheet, 'B1', f'اختلاف کشتار ', color='red', row2='C3')
|
|
|
|
create_header_freez(worksheet, excel_options, 1, 6, 7, height=22)
|
|
|
|
l = 5
|
|
m = 1
|
|
|
|
|
|
|
|
list2 = [
|
|
'مجموع==>',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
|
|
|
|
]
|
|
create_value(worksheet, list2, l + 3, 1, color='green')
|
|
workbook.save(output)
|
|
output.seek(0)
|
|
|
|
response = HttpResponse(
|
|
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
|
response[
|
|
'Content-Disposition'] = f'attachment; filename="اختلاف کشتار.xlsx"'.encode(
|
|
'utf-8')
|
|
response.write(output.getvalue())
|
|
return response
|