update excel

This commit is contained in:
2026-02-09 16:08:15 +03:30
parent ab686e86d0
commit 675c0040a6

View File

@@ -438,11 +438,23 @@ def management_poultry(request):
def hatching_excel(request): def hatching_excel(request):
filterset_class = PoultryHatchingFilterSet filterset_class = PoultryHatchingFilterSet
unknown = True if 'unknown' in request.GET else False unknown = True if 'unknown' in request.GET else False
poultry_hatch = PoultryHatching.objects.filter(archive=False, if 'all_active_and_archive' in request.GET:
allow_hatching='pending', poultry_hatch = PoultryHatching.objects.filter(
trash=False,unknown=unknown).select_related('poultry', trash=False).select_related('poultry',
'poultry__user').order_by( 'poultry__user').order_by(
'-chicken_age') '-chicken_age')
elif 'unknown' in request.GET:
poultry_hatch = PoultryHatching.objects.filter(unknown=True,
trash=False).select_related('poultry',
'poultry__user').order_by(
'-chicken_age')
else:
poultry_hatch = PoultryHatching.objects.filter(archive=False,
allow_hatching='pending',
trash=False).select_related('poultry',
'poultry__user').order_by(
'-chicken_age')
filterset_fields = [ filterset_fields = [
'poultry__user__first_name', 'poultry__user__first_name',
'poultry__user__last_name', 'poultry__user__last_name',
@@ -580,8 +592,8 @@ def hatching_excel(request):
red_font = Font(color="C00000", bold=True) red_font = Font(color="C00000", bold=True)
header_list = [ header_list = [
'تعداد فارم فعال', 'تعداد فارم ها',
'تعداد فارم دارای زنجیره فعال', 'تعداد جوجه ریزی ها',
'مجموع جوجه ریزی', 'مجموع جوجه ریزی',
'مجموع تلفات دامپزشک(قطعه)', 'مجموع تلفات دامپزشک(قطعه)',
'مجموع تلفات اتحادیه(قطعه)', 'مجموع تلفات اتحادیه(قطعه)',
@@ -739,7 +751,7 @@ def hatching_excel(request):
year=poultry_hatching.predicate_date.year year=poultry_hatching.predicate_date.year
) if poultry_hatching.predicate_date else '-' ) if poultry_hatching.predicate_date else '-'
date1 = datetime.datetime.strptime(str(poultry_hatching.date), '%Y-%m-%d %H:%M:%S') date1 = datetime.datetime.strptime(str(poultry_hatching.date), '%Y-%m-%d %H:%M:%S')
age = (datetime.datetime.now() - date1).days + 1 age = poultry_hatching.chicken_age
creator = '-' creator = '-'
if poultry_hatching.registrar: if poultry_hatching.registrar:
@@ -753,6 +765,10 @@ def hatching_excel(request):
if poultry_hatching.violation == True: if poultry_hatching.violation == True:
farm_state = 'متخلف' + ' ' + '(مانده در سالن بیش از حد مجاز)' farm_state = 'متخلف' + ' ' + '(مانده در سالن بیش از حد مجاز)'
violation += 1 violation += 1
elif poultry_hatching.archive == True:
farm_state = 'بایگانی شده'
elif poultry_hatching.unknown == True:
farm_state = 'تعیین تکمیل نشده'
if poultry_hatching.chain_company: if poultry_hatching.chain_company:
chain_company = poultry_hatching.chain_company.name chain_company = poultry_hatching.chain_company.name
all_chain_company += 1 all_chain_company += 1
@@ -849,7 +865,7 @@ def hatching_excel(request):
poultry_hatching.killed_quantity, poultry_hatching.killed_quantity,
poultry_hatching.total_killed_weight, poultry_hatching.total_killed_weight,
poultry_hatching.left_over, poultry_hatching.left_over,
f'{int(poultry_hatching.left_over * 100 / poultry_hatching.quantity)}%', f'{int(poultry_hatching.left_over * 100 / poultry_hatching.quantity) if poultry_hatching.quantity else 0}%',
left_over_ninty_percent, left_over_ninty_percent,
poultry_hatching.total_commitment, poultry_hatching.total_commitment,
poultry_hatching.governmental_quantity, poultry_hatching.governmental_quantity,
@@ -974,9 +990,10 @@ def hatching_excel(request):
export_killed_weight_final = filtered_poultry_hatch.aggregate( export_killed_weight_final = filtered_poultry_hatch.aggregate(
total_quantity=Sum('export_killed_weight')).get( total_quantity=Sum('export_killed_weight')).get(
'total_quantity', 0) or 0 'total_quantity', 0) or 0
poultry = Poultry.objects.filter(id__in=filtered_poultry_hatch.values_list('poultry', flat=True).distinct())
value_header_list = [ value_header_list = [
len(poultry),
len(filtered_poultry_hatch), len(filtered_poultry_hatch),
all_chain_company,
all_poultry_hatching_quantity, all_poultry_hatching_quantity,
all_losses, all_losses,
all_direct_losses, all_direct_losses,
@@ -1376,8 +1393,8 @@ def archive_hatching_excel(request):
cell.alignment = Alignment(horizontal='center', vertical='center') cell.alignment = Alignment(horizontal='center', vertical='center')
header_list = [ header_list = [
'تعداد فارم فعال', 'تعداد فارم ها',
'تعداد فارم دارای زنجیره فعال', 'تعداد جوجه ریزی ها',
'مجموع جوجه ریزی', 'مجموع جوجه ریزی',
'مجموع تلفات دامپزشک(قطعه)', 'مجموع تلفات دامپزشک(قطعه)',
'مجموع تلفات اتحادیه(قطعه)', 'مجموع تلفات اتحادیه(قطعه)',
@@ -1626,10 +1643,10 @@ def archive_hatching_excel(request):
accepted_real_quantity_final = bar_complete_with_kill_house.aggregate( accepted_real_quantity_final = bar_complete_with_kill_house.aggregate(
total_quantity=Sum('accepted_real_quantity')).get( total_quantity=Sum('accepted_real_quantity')).get(
'total_quantity', 0) or 0 'total_quantity', 0) or 0
poultry = Poultry.objects.filter(id__in=filtered_poultry_hatch.values_list('poultry', flat=True).distinct())
value_header_list = [ value_header_list = [
len(poultry),
len(filtered_poultry_hatch), len(filtered_poultry_hatch),
all_chain_company,
all_poultry_hatching_quantity, all_poultry_hatching_quantity,
all_losses, all_losses,
all_direct_losses, all_direct_losses,