679 lines
31 KiB
Python
679 lines
31 KiB
Python
import datetime
|
|
from io import BytesIO
|
|
from django.db.models import Sum, Q, F
|
|
from openpyxl import Workbook
|
|
from openpyxl.styles import Alignment
|
|
from django.http import HttpResponse
|
|
from panel.helper_excel import shamsi_date, create_header, excel_description, create_header_freez, create_value
|
|
from panel.models import Poultry, PoultryHatching, VetFarm, PoultryRequest, KillHouseRequest
|
|
|
|
|
|
def technical_responsible_performance_excel(request):
|
|
vat_farm = VetFarm.objects.filter(trash=False, poultry__isnull=False, vet__key=request.GET.get('key'))
|
|
poultry_id = vat_farm.values_list('poultry__id', flat=True).distinct()
|
|
poultries = Poultry.objects.filter(id__in=poultry_id, trash=False)
|
|
excel_options = [
|
|
'ردیف',
|
|
'دامپزشک فارم',
|
|
'تلفن دامپزشک فارم',
|
|
'نام واحد',
|
|
'نام و خانوادگی مالک',
|
|
'تلفن مالک',
|
|
'جوجه ریزی فعال',
|
|
'تعداد دوره جوجه ریزی',
|
|
'مجموع جوجه ریزی',
|
|
'تعداد درخواست کشتار',
|
|
'حجم درخواست کشتار',
|
|
'وزن درخواست کشتار',
|
|
'میانگین وزنی درخواست کشتار',
|
|
'تعداد بار',
|
|
'حجم بار',
|
|
'وزن بارها',
|
|
'تعداد بارهای دارای مجوز قرنطینه',
|
|
'حجم بارهای دارای کد قرنطینه',
|
|
'وزن بارهای دارای کد قرنطینه',
|
|
'تعداد بارهای فاقد مجوز قرنطینه',
|
|
'حجم بارهای فاقد کد قرنطینه',
|
|
'وزن بارهای فاقد کد قرنطینه',
|
|
'تعداد بارهای مغایرت دار',
|
|
'حجم بارهای مغایرت دار',
|
|
'وزن بارهای مغایرت دار',
|
|
'تعداد بار خارج استان',
|
|
'حجم بار خارج استان',
|
|
'وزن بار خارج استان',
|
|
'میانگین وزن خارج از استان',
|
|
|
|
]
|
|
date1 = datetime.datetime.now().date()
|
|
from_date_1 = shamsi_date(date1)
|
|
|
|
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 = [
|
|
'تعداد واحد تحت نظر',
|
|
'مجموع جوجه ریزی تحت نظر',
|
|
'مجموع درخواست کشتار',
|
|
'مجموع حجم درخواست کشتار',
|
|
'مجموع وزن درخواست کشتار',
|
|
'مجموع تعداد بارها',
|
|
'مجموع حجم بارها',
|
|
'مجموع وزن بارها',
|
|
'مجموع تعداد بارهای قرنطینه شده',
|
|
'مجموع حجم بارهای قرنطینه شده',
|
|
'مجموع وزن بارهای قرنطینه شده',
|
|
'مجموع تعداد بارهای فاقد قرنطینه',
|
|
'مجموع حجم بارهای فاقد قرنطینه',
|
|
'مجموع وزن بارهای فاقد قرنطینه نشده',
|
|
'مجموع تعداد بارهای دارای مغایرت',
|
|
'مجموع حجم بارهای دارای مغایرت',
|
|
'مجموع وزن بارهای دارای مغایرت',
|
|
'مجموع تعداد بارهای خارج استان',
|
|
'مجموع حجم بارهای خارج استان',
|
|
'مجموع وزن بارهای خارج استان',
|
|
'مجموع وزن تقریبی بارهای خارج استان',
|
|
|
|
]
|
|
header_list2 = [
|
|
'درصد قرنطینه سازی بارها',
|
|
'درصد عدم قرنطینه سازی بارها',
|
|
|
|
]
|
|
excel_description(worksheet, 'A2', 'عملکرد مسئول فنی', color='red', row2='B2')
|
|
vat_farm = vat_farm.first()
|
|
description = f'{vat_farm.vet.user.fullname}/{vat_farm.vet.user.mobile}'
|
|
excel_description(worksheet, 'A3', description, color='red', row2='B3')
|
|
|
|
create_header(worksheet, header_list, 3, 2, height=20, color='green')
|
|
|
|
create_header_freez(worksheet, excel_options, 1, 5, 6, height=22)
|
|
|
|
l = 6
|
|
m = 1
|
|
poultry_hatchings = PoultryHatching.objects.filter(poultry__in=poultries, trash=False).only('quantity', 'left_over'
|
|
)
|
|
poultry_requests = PoultryRequest.objects.filter(trash=False, poultry__in=poultries,
|
|
state_process__in=('accepted', 'pending'),
|
|
province_state__in=('accepted', 'pending')).only('quantity',
|
|
'Index_weight')
|
|
kill_requests = KillHouseRequest.objects.filter(trash=False,
|
|
province_request__poultry_request__in=poultry_requests).only(
|
|
'accepted_real_quantity', 'accepted_real_weight')
|
|
|
|
out_poultry_requests = poultry_requests.filter(out=True, out_province_request_cancel=False).only(
|
|
'quantity', 'Index_weight'
|
|
)
|
|
|
|
for poultry in poultries:
|
|
poultry_hatching = poultry_hatchings.filter(poultry=poultry)
|
|
poultry_hatching_pending = poultry_hatching.filter(state='pending', allow_hatching='pending',
|
|
archive=False).last()
|
|
|
|
hatching = 'ندارد' if not poultry_hatching_pending else f'دارد'
|
|
period='-'
|
|
if poultry_hatching_pending:
|
|
period = poultry_hatching_pending.period
|
|
else:
|
|
if poultry_hatching:
|
|
period = poultry_hatching.last().period
|
|
|
|
total_quantity = \
|
|
poultry_hatching.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
poultry_request = poultry_requests.filter(poultry=poultry)
|
|
total_quantity_poultry_request = \
|
|
poultry_request.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
total_weight_poultry_request = \
|
|
poultry_request.aggregate(total=Sum(F('quantity') * F('Index_weight')))[
|
|
'total'] or 0
|
|
total_index_weight_poultry_request = \
|
|
poultry_request.aggregate(total=Sum('Index_weight'))[
|
|
'total'] or 0
|
|
index_weight = round(total_index_weight_poultry_request / len(poultry_request), 2) if len(
|
|
poultry_request) > 0 else 0
|
|
kill_request = kill_requests.filter(province_request__poultry_request__in=poultry_request)
|
|
kill_request_quantity = kill_request.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight = kill_request.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
has_code = kill_request.filter(clearance_code__isnull=False)
|
|
kill_request_quantity_has_code = has_code.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_has_code = has_code.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
hasnt_code = kill_request.filter(clearance_code__isnull=True)
|
|
kill_request_quantity_hasnt_code = hasnt_code.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_hasnt_code = hasnt_code.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
deffrent_bar = kill_request.filter(
|
|
~Q(quantity=F('quarantine_quantity')
|
|
, quarantine_quantity__isnull=False))
|
|
kill_request_quantity_deffrent_bar = deffrent_bar.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_deffrent_bar = deffrent_bar.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
out_poultry_request = out_poultry_requests.filter(poultry=poultry)
|
|
total_quantity_poultry_request_out = \
|
|
out_poultry_request.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
total_weight_poultry_request_out = \
|
|
out_poultry_request.aggregate(total=Sum(F('quantity') * F('Index_weight')))[
|
|
'total'] or 0
|
|
total_index_weight_poultry_request_out = \
|
|
out_poultry_request.aggregate(total=Sum('Index_weight'))[
|
|
'total'] or 0
|
|
index_weight_out = round(total_index_weight_poultry_request_out / len(out_poultry_request), 2) if len(
|
|
out_poultry_request) > 0 else 0
|
|
|
|
list1 = [
|
|
m,
|
|
vat_farm.vet.user.fullname,
|
|
vat_farm.vet.user.mobile,
|
|
poultry.unit_name,
|
|
poultry.user.fullname,
|
|
poultry.user.mobile,
|
|
hatching,
|
|
period,
|
|
total_quantity,
|
|
len(poultry_request),
|
|
total_quantity_poultry_request,
|
|
total_weight_poultry_request,
|
|
index_weight,
|
|
len(kill_request),
|
|
kill_request_quantity,
|
|
kill_request_weight,
|
|
len(has_code),
|
|
kill_request_quantity_has_code,
|
|
kill_request_weight_has_code,
|
|
len(hasnt_code),
|
|
kill_request_quantity_hasnt_code,
|
|
kill_request_weight_hasnt_code,
|
|
len(deffrent_bar),
|
|
kill_request_quantity_deffrent_bar,
|
|
kill_request_weight_deffrent_bar,
|
|
len(out_poultry_request),
|
|
total_quantity_poultry_request_out,
|
|
total_weight_poultry_request_out,
|
|
index_weight_out,
|
|
]
|
|
create_value(worksheet, list1, l, 1)
|
|
m += 1
|
|
l += 1
|
|
total_quantity = \
|
|
poultry_hatchings.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
total_quantity_poultry_request = \
|
|
poultry_requests.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
total_weight_poultry_request = \
|
|
poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[
|
|
'total'] or 0
|
|
kill_request_quantity = kill_requests.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight = kill_requests.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
has_code = kill_requests.filter(clearance_code__isnull=False)
|
|
kill_request_quantity_has_code = has_code.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_has_code = has_code.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
|
|
deffrent_bar = kill_requests.filter(
|
|
~Q(quantity=F('quarantine_quantity')
|
|
, quarantine_quantity__isnull=False))
|
|
kill_request_quantity_deffrent_bar = deffrent_bar.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_deffrent_bar = deffrent_bar.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
hasnt_code = kill_requests.filter(clearance_code__isnull=True)
|
|
kill_request_quantity_hasnt_code = hasnt_code.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_hasnt_code = hasnt_code.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
total_quantity_poultry_request_out = \
|
|
out_poultry_requests.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
total_weight_poultry_request_out = \
|
|
out_poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[
|
|
'total'] or 0
|
|
total_index_weight_poultry_request_out = \
|
|
out_poultry_requests.aggregate(total=Sum('Index_weight'))[
|
|
'total'] or 0
|
|
index_weight_out = round(total_index_weight_poultry_request_out / len(out_poultry_requests), 2) if len(
|
|
out_poultry_requests) > 0 else 0
|
|
list2 = [
|
|
'مجموع==>',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
total_quantity,
|
|
len(poultry_requests),
|
|
total_quantity_poultry_request,
|
|
total_weight_poultry_request,
|
|
'',
|
|
len(kill_requests),
|
|
kill_request_quantity,
|
|
kill_request_weight,
|
|
len(has_code),
|
|
kill_request_quantity_has_code,
|
|
kill_request_weight_has_code,
|
|
len(hasnt_code),
|
|
kill_request_quantity_hasnt_code,
|
|
kill_request_weight_hasnt_code,
|
|
len(deffrent_bar),
|
|
kill_request_quantity_deffrent_bar,
|
|
kill_request_weight_deffrent_bar,
|
|
len(out_poultry_requests),
|
|
total_quantity_poultry_request_out,
|
|
total_weight_poultry_request_out,
|
|
index_weight_out,
|
|
|
|
]
|
|
|
|
create_value(worksheet, list2, l + 2, 1, color='green')
|
|
|
|
value_header_list = [
|
|
len(poultries),
|
|
total_quantity,
|
|
len(poultry_requests),
|
|
total_quantity_poultry_request,
|
|
total_weight_poultry_request,
|
|
len(kill_requests),
|
|
kill_request_quantity,
|
|
kill_request_weight,
|
|
len(has_code),
|
|
kill_request_quantity_has_code,
|
|
kill_request_weight_has_code,
|
|
len(hasnt_code),
|
|
kill_request_quantity_hasnt_code,
|
|
kill_request_weight_hasnt_code,
|
|
len(deffrent_bar),
|
|
kill_request_quantity_deffrent_bar,
|
|
kill_request_weight_deffrent_bar,
|
|
len(out_poultry_requests),
|
|
total_quantity_poultry_request_out,
|
|
total_weight_poultry_request_out,
|
|
index_weight_out,
|
|
]
|
|
create_value(worksheet, value_header_list, 3, 3)
|
|
workbook.save(output)
|
|
output.seek(0)
|
|
|
|
response = HttpResponse(
|
|
content_type='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|
|
response[
|
|
'Content-Disposition'] = f'attachment; filename="عملکرد مسئول فنی({vat_farm.vet.user.fullname}).xlsx"'.encode(
|
|
'utf-8')
|
|
response.write(output.getvalue())
|
|
return response
|
|
|
|
def totoal_technical_responsible_performance_excel(request):
|
|
vat_farm = VetFarm.objects.filter(trash=False, poultry__isnull=False)
|
|
poultry_id = vat_farm.values_list('poultry__id', flat=True).distinct()
|
|
poultries = Poultry.objects.filter(id__in=poultry_id, trash=False)
|
|
excel_options = [
|
|
'ردیف',
|
|
'دامپزشک فارم',
|
|
'تلفن دامپزشک فارم',
|
|
'تعداد واحد تحت نظر',
|
|
'مجموع جوجه ریزی تحت نظر',
|
|
'مجموع درخواست کشتار',
|
|
'مجموع حجم درخواست کشتار',
|
|
'مجموع وزن درخواست کشتار',
|
|
'مجموع تعداد بارها',
|
|
'مجموع حجم بارها',
|
|
'مجموع وزن بارها',
|
|
'مجموع تعداد بارهای قرنطینه شده',
|
|
'مجموع حجم بارهای قرنطینه شده',
|
|
'مجموع وزن بارهای قرنطینه شده',
|
|
'مجموع تعداد بارهای فاقد قرنطینه',
|
|
'مجموع حجم بارهای فاقد قرنطینه',
|
|
'مجموع وزن بارهای فاقد قرنطینه نشده',
|
|
'مجموع تعداد بارهای دارای مغایرت',
|
|
'مجموع حجم بارهای دارای مغایرت',
|
|
'مجموع وزن بارهای دارای مغایرت',
|
|
'مجموع تعداد بارهای خارج استان',
|
|
'مجموع حجم بارهای خارج استان',
|
|
'مجموع وزن بارهای خارج استان',
|
|
'مجموع وزن تقریبی بارهای خارج استان',
|
|
|
|
]
|
|
date1 = datetime.datetime.now().date()
|
|
from_date_1 = shamsi_date(date1)
|
|
|
|
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 = [
|
|
'تعداد واحد تحت نظر',
|
|
'مجموع جوجه ریزی تحت نظر',
|
|
'مجموع درخواست کشتار',
|
|
'مجموع حجم درخواست کشتار',
|
|
'مجموع وزن درخواست کشتار',
|
|
'مجموع تعداد بارها',
|
|
'مجموع حجم بارها',
|
|
'مجموع وزن بارها',
|
|
'مجموع تعداد بارهای قرنطینه شده',
|
|
'مجموع حجم بارهای قرنطینه شده',
|
|
'مجموع وزن بارهای قرنطینه شده',
|
|
'مجموع تعداد بارهای فاقد قرنطینه',
|
|
'مجموع حجم بارهای فاقد قرنطینه',
|
|
'مجموع وزن بارهای فاقد قرنطینه نشده',
|
|
'مجموع تعداد بارهای دارای مغایرت',
|
|
'مجموع حجم بارهای دارای مغایرت',
|
|
'مجموع وزن بارهای دارای مغایرت',
|
|
'مجموع تعداد بارهای خارج استان',
|
|
'مجموع حجم بارهای خارج استان',
|
|
'مجموع وزن بارهای خارج استان',
|
|
'مجموع وزن تقریبی بارهای خارج استان',
|
|
|
|
]
|
|
|
|
excel_description(worksheet, 'A2', 'عملکرد مسئول فنی', color='red', row2='B2')
|
|
|
|
|
|
create_header(worksheet, header_list, 3, 2, height=20, color='green')
|
|
|
|
create_header_freez(worksheet, excel_options, 1, 5, 6, height=22)
|
|
|
|
l = 6
|
|
m = 1
|
|
poultry_hatchings = PoultryHatching.objects.filter(poultry__in=poultries, trash=False).only('quantity', 'left_over')
|
|
if 'date1' in request.GET:
|
|
date1 = datetime.datetime.strptime(request.GET['date1'],
|
|
'%Y-%m-%d').date()
|
|
date2 = datetime.datetime.strptime(request.GET['date2'],
|
|
'%Y-%m-%d').date()
|
|
poultry_requests = PoultryRequest.objects.filter(send_date__date__gte=date1,send_date__date__lte=date2,trash=False, poultry__in=poultries,
|
|
state_process__in=('accepted', 'pending'),
|
|
province_state__in=('accepted', 'pending')).only('quantity',
|
|
'Index_weight')
|
|
kill_requests = KillHouseRequest.objects.filter(kill_request__recive_date__date__gte=date1,kill_request__recive_date__date__lte=date2,trash=False,
|
|
province_request__poultry_request__in=poultry_requests).only(
|
|
'accepted_real_quantity', 'accepted_real_weight')
|
|
else:
|
|
poultry_requests = PoultryRequest.objects.filter(trash=False, poultry__in=poultries,
|
|
state_process__in=('accepted', 'pending'),
|
|
province_state__in=('accepted', 'pending')).only('quantity',
|
|
'Index_weight')
|
|
|
|
kill_requests = KillHouseRequest.objects.filter(trash=False,
|
|
province_request__poultry_request__in=poultry_requests).only(
|
|
'accepted_real_quantity', 'accepted_real_weight')
|
|
|
|
|
|
out_poultry_requests = poultry_requests.filter(out=True, out_province_request_cancel=False).only(
|
|
'quantity', 'Index_weight'
|
|
)
|
|
for vet in vat_farm:
|
|
poultry = Poultry.objects.filter(id=vet.poultry.id, trash=False)
|
|
poultry_hatchings = PoultryHatching.objects.filter(poultry__in=poultry, trash=False).only('quantity',
|
|
'left_over')
|
|
if 'date1' in request.GET:
|
|
date1 = datetime.datetime.strptime(request.GET['date1'],
|
|
'%Y-%m-%d').date()
|
|
date2 = datetime.datetime.strptime(request.GET['date2'],
|
|
'%Y-%m-%d').date()
|
|
poultry_requests = PoultryRequest.objects.filter(send_date__date__gte=date1, send_date__date__lte=date2,
|
|
trash=False, poultry__in=poultry,
|
|
state_process__in=('accepted', 'pending'),
|
|
province_state__in=('accepted', 'pending')).only(
|
|
'quantity',
|
|
'Index_weight')
|
|
kill_requests = KillHouseRequest.objects.filter(kill_request__recive_date__date__gte=date1,
|
|
kill_request__recive_date__date__lte=date2, trash=False,
|
|
province_request__poultry_request__in=poultry).only(
|
|
'accepted_real_quantity', 'accepted_real_weight')
|
|
else:
|
|
poultry_requests = PoultryRequest.objects.filter(trash=False, poultry__in=poultry,
|
|
state_process__in=('accepted', 'pending'),
|
|
province_state__in=('accepted', 'pending')).only(
|
|
'quantity',
|
|
'Index_weight')
|
|
|
|
kill_requests = KillHouseRequest.objects.filter(trash=False,
|
|
province_request__poultry_request__in=poultry_requests).only(
|
|
'accepted_real_quantity', 'accepted_real_weight')
|
|
|
|
out_poultry_requests = poultry_requests.filter(out=True, out_province_request_cancel=False).only(
|
|
'quantity', 'Index_weight'
|
|
)
|
|
poultry_hatching = poultry_hatchings.filter(poultry=poultries)
|
|
total_quantity = \
|
|
poultry_hatching.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
poultry_request = poultry_requests.filter(poultry=poultry)
|
|
total_quantity_poultry_request = \
|
|
poultry_request.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
total_weight_poultry_request = \
|
|
poultry_request.aggregate(total=Sum(F('quantity') * F('Index_weight')))[
|
|
'total'] or 0
|
|
total_index_weight_poultry_request = \
|
|
poultry_request.aggregate(total=Sum('Index_weight'))[
|
|
'total'] or 0
|
|
index_weight = round(total_index_weight_poultry_request / len(poultry_request), 2) if len(
|
|
poultry_request) > 0 else 0
|
|
kill_request = kill_requests.filter(province_request__poultry_request__in=poultry_request)
|
|
kill_request_quantity = kill_request.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight = kill_request.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
has_code = kill_request.filter(clearance_code__isnull=False)
|
|
kill_request_quantity_has_code = has_code.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_has_code = has_code.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
hasnt_code = kill_request.filter(clearance_code__isnull=True)
|
|
kill_request_quantity_hasnt_code = hasnt_code.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_hasnt_code = hasnt_code.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
deffrent_bar = kill_request.filter(
|
|
~Q(quantity=F('quarantine_quantity')
|
|
, quarantine_quantity__isnull=False))
|
|
kill_request_quantity_deffrent_bar = deffrent_bar.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_deffrent_bar = deffrent_bar.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
out_poultry_request = out_poultry_requests.filter(poultry=poultry)
|
|
total_quantity_poultry_request_out = \
|
|
out_poultry_request.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
total_weight_poultry_request_out = \
|
|
out_poultry_request.aggregate(total=Sum(F('quantity') * F('Index_weight')))[
|
|
'total'] or 0
|
|
total_index_weight_poultry_request_out = \
|
|
out_poultry_request.aggregate(total=Sum('Index_weight'))[
|
|
'total'] or 0
|
|
index_weight_out = round(total_index_weight_poultry_request_out / len(out_poultry_request), 2) if len(
|
|
out_poultry_request) > 0 else 0
|
|
|
|
list1 = [
|
|
m,
|
|
vet.vet.user.fullname,
|
|
vet.vet.user.mobile,
|
|
len(poultries),
|
|
total_quantity,
|
|
len(poultry_requests),
|
|
total_quantity_poultry_request,
|
|
total_weight_poultry_request,
|
|
len(kill_requests),
|
|
kill_request_quantity,
|
|
kill_request_weight,
|
|
len(has_code),
|
|
kill_request_quantity_has_code,
|
|
kill_request_weight_has_code,
|
|
len(hasnt_code),
|
|
kill_request_quantity_hasnt_code,
|
|
kill_request_weight_hasnt_code,
|
|
len(deffrent_bar),
|
|
kill_request_quantity_deffrent_bar,
|
|
kill_request_weight_deffrent_bar,
|
|
len(out_poultry_requests),
|
|
total_quantity_poultry_request_out,
|
|
total_weight_poultry_request_out,
|
|
index_weight_out,
|
|
]
|
|
create_value(worksheet, list1, l, 1)
|
|
m += 1
|
|
l += 1
|
|
total_quantity = \
|
|
poultry_hatchings.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
total_quantity_poultry_request = \
|
|
poultry_requests.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
total_weight_poultry_request = \
|
|
poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[
|
|
'total'] or 0
|
|
kill_request_quantity = kill_requests.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight = kill_requests.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
has_code = kill_requests.filter(clearance_code__isnull=False)
|
|
kill_request_quantity_has_code = has_code.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_has_code = has_code.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
|
|
deffrent_bar = kill_requests.filter(
|
|
~Q(quantity=F('quarantine_quantity')
|
|
, quarantine_quantity__isnull=False))
|
|
kill_request_quantity_deffrent_bar = deffrent_bar.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_deffrent_bar = deffrent_bar.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
hasnt_code = kill_requests.filter(clearance_code__isnull=True)
|
|
kill_request_quantity_hasnt_code = hasnt_code.aggregate(
|
|
total=Sum('accepted_real_quantity'))[
|
|
'total'] or 0
|
|
kill_request_weight_hasnt_code = hasnt_code.aggregate(
|
|
total=Sum('accepted_real_weight'))[
|
|
'total'] or 0
|
|
total_quantity_poultry_request_out = \
|
|
out_poultry_requests.aggregate(total=Sum('quantity'))[
|
|
'total'] or 0
|
|
total_weight_poultry_request_out = \
|
|
out_poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[
|
|
'total'] or 0
|
|
total_index_weight_poultry_request_out = \
|
|
out_poultry_requests.aggregate(total=Sum('Index_weight'))[
|
|
'total'] or 0
|
|
index_weight_out = round(total_index_weight_poultry_request_out / len(out_poultry_requests), 2) if len(
|
|
out_poultry_requests) > 0 else 0
|
|
list2 = [
|
|
'مجموع==>',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
'',
|
|
total_quantity,
|
|
len(poultry_requests),
|
|
total_quantity_poultry_request,
|
|
total_weight_poultry_request,
|
|
'',
|
|
len(kill_requests),
|
|
kill_request_quantity,
|
|
kill_request_weight,
|
|
len(has_code),
|
|
kill_request_quantity_has_code,
|
|
kill_request_weight_has_code,
|
|
len(hasnt_code),
|
|
kill_request_quantity_hasnt_code,
|
|
kill_request_weight_hasnt_code,
|
|
len(deffrent_bar),
|
|
kill_request_quantity_deffrent_bar,
|
|
kill_request_weight_deffrent_bar,
|
|
len(out_poultry_requests),
|
|
total_quantity_poultry_request_out,
|
|
total_weight_poultry_request_out,
|
|
index_weight_out,
|
|
|
|
]
|
|
|
|
create_value(worksheet, list2, l + 2, 1, color='green')
|
|
|
|
value_header_list = [
|
|
len(poultries),
|
|
total_quantity,
|
|
len(poultry_requests),
|
|
total_quantity_poultry_request,
|
|
total_weight_poultry_request,
|
|
len(kill_requests),
|
|
kill_request_quantity,
|
|
kill_request_weight,
|
|
len(has_code),
|
|
kill_request_quantity_has_code,
|
|
kill_request_weight_has_code,
|
|
len(hasnt_code),
|
|
kill_request_quantity_hasnt_code,
|
|
kill_request_weight_hasnt_code,
|
|
len(deffrent_bar),
|
|
kill_request_quantity_deffrent_bar,
|
|
kill_request_weight_deffrent_bar,
|
|
len(out_poultry_requests),
|
|
total_quantity_poultry_request_out,
|
|
total_weight_poultry_request_out,
|
|
index_weight_out,
|
|
]
|
|
create_value(worksheet, value_header_list, 3, 3)
|
|
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 |