add get_kill_houses_out_buying_info

This commit is contained in:
2026-01-26 11:07:20 +03:30
parent 03e2c35b68
commit 51a764daac
2 changed files with 107 additions and 1 deletions

View File

@@ -798,6 +798,109 @@ def get_finance_info(kill_house, date1=None, date2=None):
"difference_requests_price": difference_requests_price,
}
def get_kill_houses_out_buying_info(kill_houses, date1=None, date2=None):
final_out_live_buying_province_carcasses_weight = 0
before_total_out_live_buying_province_carcasses_weight = 0
after_total_out_live_buying_province_carcasses_weight = 0
before_new_out_selling = 0
after_new_out_selling = 0
extra_company_amount = 0
total_wage_type = WageType.objects.filter(trash=False)
province_live_wage_type = total_wage_type.filter(en_name='province-kill-request', trash=False).first()
free_buying_live_weight_wage_type = total_wage_type.filter(en_name='live-buy', trash=False).first()
free_buying_carcesses_weight_wage_type = total_wage_type.filter(en_name='carcasse-buy', trash=False).first()
free_sell_carcesses_weight_wage_type = total_wage_type.filter(en_name='carcasse-sell', trash=False).first()
province_live_wage_type_amount = province_live_wage_type.amount if province_live_wage_type.status == True else 0
free_buying_live_weight_wage_type_amount = free_buying_live_weight_wage_type.amount if free_buying_live_weight_wage_type.status == True else 0
free_buying_carcesses_weight_wage_type_amount = free_buying_carcesses_weight_wage_type.amount if free_buying_carcesses_weight_wage_type.status == True else 0
free_sell_carcesses_weight_wage_type_amount = free_sell_carcesses_weight_wage_type.amount if free_sell_carcesses_weight_wage_type.status == True else 0
for kill_house in kill_houses:
if date1:
kill_house_free_bar_info = KillHouseFreeBarInformation.objects.filter(
Q(kill_house=kill_house) | Q(exclusive_killer=kill_house),
archive_wage=False,
calculate_status=True, date__date__gte=date1, date__date__lte=date2,
trash=False)
kill_house_free_sale_bar_info = KillHouseFreeSaleBarInformation.objects.filter(
kill_house=kill_house,
archive_wage=False,
calculate_status=True, date__date__gte=date1, date__date__lte=date2,
trash=False)
else:
kill_house_free_bar_info = KillHouseFreeBarInformation.objects.filter(
Q(kill_house=kill_house) | Q(exclusive_killer=kill_house),
archive_wage=False,
calculate_status=True,
trash=False)
kill_house_free_sale_bar_info = KillHouseFreeSaleBarInformation.objects.filter(
kill_house=kill_house,
archive_wage=False,
calculate_status=True,
trash=False)
final_date = '2025-05-28'
total_out_selling_province_carcasses_weight = \
kill_house_free_sale_bar_info.filter(date__date__lte=final_date).aggregate(
total=Sum('real_weight_of_carcasses'))['total'] or 0
new_total_out_selling_province_carcasses_weight = \
kill_house_free_sale_bar_info.filter(date__date__gt=final_date,
quarantine_weight_of_carcasses__gt=0).aggregate(
total_weight=Sum(
Case(
When(real_weight_of_carcasses__lt=F('quarantine_weight_of_carcasses'),
then=F('real_weight_of_carcasses')),
default=F('quarantine_weight_of_carcasses'),
output_field=FloatField()
)
)
)
new_out_selling = new_total_out_selling_province_carcasses_weight['total_weight'] or 0
total_out_selling_province_carcasses_weight += new_out_selling
total_out_live_buying_province_carcasses_weight = \
kill_house_free_bar_info.filter(buy_type='live').aggregate(total=Sum('live_weight'))['total'] or 0
if new_out_selling_count_wage:
if out_selling_ignore:
before_total_out_live_buying_province_carcasses_weight = \
kill_house_free_bar_info.filter(create_date__date__lt=new_out_selling_count_wage_date,
buy_type='live').aggregate(total=Sum('live_weight'))['total'] or 0
after_total_out_live_buying_province_carcasses_weight = \
kill_house_free_bar_info.filter(create_date__date__gte=new_out_selling_count_wage_date,
buy_type='live').aggregate(total=Sum('live_weight'))['total'] or 0
get_new_wage = get_new_wage_for_free_buying(kill_house_free_sale_bar_info)
before_new_out_selling = get_new_wage['before_new_out_selling']
after_new_out_selling = get_new_wage['after_new_out_selling']
max_amount = before_total_out_live_buying_province_carcasses_weight * 0.80
if max_amount <= before_new_out_selling:
before_total_out_live_buying_province_carcasses_weight -= max_amount
else:
before_total_out_live_buying_province_carcasses_weight -= before_new_out_selling
if after_total_out_live_buying_province_carcasses_weight > after_new_out_selling:
extra_company_amount = int(after_new_out_selling * extra_company_amount)
after_total_out_live_buying_province_carcasses_weight -= after_new_out_selling
else:
extra_company_amount = int(after_total_out_live_buying_province_carcasses_weight * extra_company_amount)
after_total_out_live_buying_province_carcasses_weight = 0
total_out_live_buying_province_carcasses_weight = before_total_out_live_buying_province_carcasses_weight + after_total_out_live_buying_province_carcasses_weight
else:
if out_selling_ignore:
max_amount = total_out_live_buying_province_carcasses_weight * 0.80
if max_amount <= new_out_selling:
total_out_live_buying_province_carcasses_weight -= max_amount
else:
total_out_live_buying_province_carcasses_weight -= new_out_selling
final_out_live_buying_province_carcasses_weight +=total_out_live_buying_province_carcasses_weight
print(final_out_live_buying_province_carcasses_weight)
return final_out_live_buying_province_carcasses_weight
def get_kill_house_finance_info(kill_house, date1=None, date2=None):

View File

@@ -21,7 +21,8 @@ from deposit_id import wage_counting_type, out_selling_ignore, new_out_selling_c
from deposit_percent import wage_percent, carcases_sell
from general_urls import base_url_for_sms_report
from panel.CityOperator.serializers import CityOperatorForSubSectorTransactionsSerializer
from panel.KillHouse.helpers import get_finance_info, get_difference_carcasses_weight, get_new_wage_for_free_buying
from panel.KillHouse.helpers import get_finance_info, get_difference_carcasses_weight, get_new_wage_for_free_buying, \
get_kill_houses_out_buying_info
from panel.KillHouse.serializers import VetSerializer, ProvinceKillRequestSerializer, \
KillHouseAssignmentInformationSerializer, KillHouseSerializer, KillHouseDailyQuotaSerializer, \
ProvinceKillRequestForAutoAllocationSerializer, KillHouseWareHouseSerializer, KillHouseForProvinceSerializer, \
@@ -4351,6 +4352,8 @@ class TotalWageInformationSerializer(serializers.ModelSerializer):
else:
total_out_live_buying_province_carcasses_weight -= new_out_selling
total_out_live_buying_province_carcasses_weight = get_kill_houses_out_buying_info(kill_houses)
total_out_carcasses_buying_province_carcasses_weight = \
kill_house_free_bar_info.filter(buy_type='carcass').aggregate(total=Sum('weight_of_carcasses'))[
'total'] or 0