update warehouse excel and urls
This commit is contained in:
@@ -38,7 +38,7 @@ class SaveLog:
|
||||
'method': request.method,
|
||||
'remote_address': self.get_client_ip(request),
|
||||
'exec_time': _t,
|
||||
'body_response': response.content.decode('utf-8'),
|
||||
# 'body_response': response.content.decode('utf-8'),
|
||||
'body_request': request.POST,
|
||||
'client_ip': self.get_client_ip(request),
|
||||
'browser_info': request.META['HTTP_USER_AGENT'],
|
||||
|
||||
0
apps/warehouse/services/excel/__init__.py
Normal file
0
apps/warehouse/services/excel/__init__.py
Normal file
85
apps/warehouse/services/excel/excel_processing.py
Normal file
85
apps/warehouse/services/excel/excel_processing.py
Normal file
@@ -0,0 +1,85 @@
|
||||
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
|
||||
11
apps/warehouse/services/excel/urls.py
Normal file
11
apps/warehouse/services/excel/urls.py
Normal file
@@ -0,0 +1,11 @@
|
||||
from django.urls import path, include
|
||||
from rest_framework.routers import DefaultRouter
|
||||
from apps.warehouse.services.excel import excel_processing as excel
|
||||
from apps.warehouse.services.excel.excel_processing import warehouse_excel
|
||||
|
||||
router = DefaultRouter()
|
||||
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
path('warehouse_excel/', warehouse_excel),
|
||||
]
|
||||
@@ -3,5 +3,7 @@ from django.urls import path, include
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
path('web/api/', include('apps.warehouse.web.api.v1.urls'))
|
||||
path('web/api/', include('apps.warehouse.web.api.v1.urls')),
|
||||
path('excel/', include('apps.warehouse.services.excel.urls')),
|
||||
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user