update for wage

This commit is contained in:
2026-01-28 08:41:09 +03:30
parent 16665372da
commit 3b34441efc
2 changed files with 1069 additions and 1201 deletions

View File

@@ -800,6 +800,329 @@ def get_finance_info(kill_house, date1=None, date2=None):
}
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_total_wage_info(kill_house):
total_wage = 0
total_paid_wage = 0
off = 0
total_unpaid_wage = 0
province_kill_requests_total_wage = 0
province_kill_requests_total_weight = 0
free_bars_live_total_wage = 0
free_bars_live_total_weight = 0
free_bars_carcases_total_wage = 0
free_bars_carcases_total_weight = 0
free_bars_out_province_carcases_total_wage = 0
free_bars_out_province_carcases_total_weight = 0
total_province_live_weight = 0
total_province_carcasses_weight = 0
province_live_wage_amount = 0
free_buying_live_weight_amount = 0
free_buying_carcesses_weight_amount = 0
free_sell_carcesses_weight_amount = 0
return_total_province_live_weight = 0
total_return_pure_province_carcasses_price = 0
total_pure_province_carcasses_price = 0
return_total_pure_province_carcasses_price = 0
total_out_selling_province_carcasses_price = 0
difference_requests_price = 0
before_total_out_live_buying_province_carcasses_price = 0
total_out_live_buying_province_carcasses_price = 0
total_out_carcasses_buying_province_carcasses_price = 0
guilds_difference_requests_price = 0
other_difference_requests_price = 0
guild_return_province_kill_request_wage = 0
other_return_province_kill_request_wage = 0
before_total_out_live_buying_province_carcasses_price = 0
total_wage_type = WageType.objects.filter(trash=False)
free_buying_live_weight_wage_type = total_wage_type.filter(en_name='live-buy', trash=False).first()
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
finance_info = get_finance_info(kill_house)
if kill_house.killer and kill_house.type == 'public':
slaughter_transactions = InternalTransaction.objects.filter(
kill_house=kill_house, parent_kill_house=kill_house, status='completed',
trash=False)
else:
slaughter_transactions = InternalTransaction.objects.filter(
Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), status='completed',
trash=False)
total_paid_wage += slaughter_transactions.aggregate(total=Sum('amount'))[
'total'] or 0
total_pure_province_carcasses_price = finance_info['total_pure_province_carcasses_price']
return_total_pure_province_carcasses_price = finance_info['total_return_pure_province_carcasses_price']
total_out_selling_province_carcasses_price = finance_info['total_out_selling_province_carcasses_price']
difference_requests_price = finance_info['difference_requests_price']
if new_out_selling_count_wage:
total_out_live_buying_province_carcasses_price = int(
(finance_info[
'before_total_out_live_buying_province_carcasses_weight'] * before_out_buying_count_wage_amount) + (
finance_info[
'after_total_out_live_buying_province_carcasses_weight'] * free_buying_live_weight_wage_type_amount))
before_total_out_live_buying_province_carcasses_price = finance_info[
'before_total_out_live_buying_province_carcasses_weight'] * before_out_buying_count_wage_amount
else:
total_out_live_buying_province_carcasses_price = finance_info[
'total_out_live_buying_province_carcasses_price']
total_out_carcasses_buying_province_carcasses_price = finance_info[
'total_out_carcasses_buying_province_carcasses_price']
percentages_wage_type = PercentageOfWageType.objects.filter(trash=False)
union_province_kill_request_percent = percentages_wage_type.filter(
wage_type__en_name='province-kill-request', share_type__en_name='union').first().percent / 100
company_province_kill_request_percent = percentages_wage_type.filter(
wage_type__en_name='province-kill-request', share_type__en_name='company').first().percent / 100
guilds_province_kill_request_percent = percentages_wage_type.filter(
wage_type__en_name='province-kill-request', share_type__en_name='guilds').first().percent / 100
other_province_kill_request_percent = percentages_wage_type.filter(
wage_type__en_name='province-kill-request', share_type__en_name='other').first().percent / 100
union_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy',
share_type__en_name='union').first().percent / 100
union_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy',
share_type__en_name='union').first().percent / 100
company_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy',
share_type__en_name='company').first().percent / 100
company_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy',
share_type__en_name='company').first().percent / 100
guilds_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy',
share_type__en_name='guilds').first().percent / 100
guilds_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy',
share_type__en_name='guilds').first().percent / 100
other_free_buying_live_percent = percentages_wage_type.filter(wage_type__en_name='live-buy',
share_type__en_name='other').first().percent / 100
other_free_buying_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-buy',
share_type__en_name='other').first().percent / 100
union_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell',
share_type__en_name='union').first().percent / 100
company_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell',
share_type__en_name='company').first().percent / 100
guilds_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell',
share_type__en_name='guilds').first().percent / 100
other_free_sell_carcasses_percent = percentages_wage_type.filter(wage_type__en_name='carcasse-sell',
share_type__en_name='other').first().percent / 100
guilds_difference_requests_price = difference_requests_price * guilds_province_kill_request_percent
other_difference_requests_price = difference_requests_price * other_province_kill_request_percent
guild_return_province_kill_request_wage = return_total_pure_province_carcasses_price * guilds_province_kill_request_percent
other_return_province_kill_request_wage = return_total_pure_province_carcasses_price * other_province_kill_request_percent
union_province_kill_request_wage = total_pure_province_carcasses_price * union_province_kill_request_percent
return_union_province_kill_request_wage = return_total_pure_province_carcasses_price * union_province_kill_request_percent
union_free_buying_live_wage = (
total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * union_free_buying_live_percent
union_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * union_free_buying_carcasses_percent
union_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * union_free_sell_carcasses_percent
union_total_wage = union_province_kill_request_wage + union_free_buying_live_wage + union_free_buying_carcasses_wage + union_free_sell_carcasses_wage + return_union_province_kill_request_wage
union_total_paid_wage = slaughter_transactions.aggregate(total=Sum('union_share'))['total'] or 0
union_total_unpaid_wage = union_total_wage - union_total_paid_wage
company_province_kill_request_wage = (
total_pure_province_carcasses_price * company_province_kill_request_percent) + (
guilds_difference_requests_price + other_difference_requests_price)
return_company_province_kill_request_wage = (
return_total_pure_province_carcasses_price * company_province_kill_request_percent) + (
guild_return_province_kill_request_wage + other_return_province_kill_request_wage)
company_free_buying_live_wage = ((
total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * company_free_buying_live_percent) + before_total_out_live_buying_province_carcasses_price
company_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * company_free_buying_carcasses_percent
company_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * company_free_sell_carcasses_percent
company_total_wage = company_province_kill_request_wage + company_free_buying_live_wage + company_free_buying_carcasses_wage + company_free_sell_carcasses_wage + return_company_province_kill_request_wage
company_total_paid_wage = slaughter_transactions.aggregate(total=Sum('company_share'))['total'] or 0
company_total_unpaid_wage = company_total_wage - company_total_paid_wage
guilds_province_kill_request_wage = (
total_pure_province_carcasses_price * guilds_province_kill_request_percent) - guilds_difference_requests_price
return_guilds_province_kill_request_wage = 0
guilds_free_buying_live_wage = (
total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * guilds_free_buying_live_percent
guilds_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * guilds_free_buying_carcasses_percent
guilds_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * guilds_free_sell_carcasses_percent
guilds_total_wage = guilds_province_kill_request_wage + guilds_free_buying_live_wage + guilds_free_buying_carcasses_wage + guilds_free_sell_carcasses_wage
guilds_total_paid_wage = slaughter_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0
guilds_total_unpaid_wage = guilds_total_wage - guilds_total_paid_wage
other_province_kill_request_wage = (
total_pure_province_carcasses_price * other_province_kill_request_percent) - other_difference_requests_price
return_other_province_kill_request_wage = 0
other_free_buying_live_wage = (
total_out_live_buying_province_carcasses_price - before_total_out_live_buying_province_carcasses_price) * other_free_buying_live_percent
other_free_buying_carcasses_wage = total_out_carcasses_buying_province_carcasses_price * other_free_buying_carcasses_percent
other_free_sell_carcasses_wage = total_out_selling_province_carcasses_price * other_free_sell_carcasses_percent
other_total_wage = other_province_kill_request_wage + other_free_buying_live_wage + other_free_buying_carcasses_wage + other_free_sell_carcasses_wage
other_total_paid_wage = slaughter_transactions.aggregate(total=Sum('other_share'))['total'] or 0
other_total_unpaid_wage = other_total_wage - other_total_paid_wage
result = {
"wage_counting_type": wage_counting_type,
"total_wage": finance_info['total_price'],
"total_paid_wage": total_paid_wage,
"off": kill_house.off,
"total_unpaid_wage": finance_info['total_price'] - (total_paid_wage + kill_house.off),
"province_kill_requests_total_wage": finance_info['total_pure_province_carcasses_price'],
"province_kill_requests_total_weight": finance_info['total_pure_province_carcasses_weight'],
"free_bars_live_total_wage": finance_info['total_out_live_buying_province_carcasses_price'],
"free_bars_live_total_weight": finance_info['total_out_live_buying_province_carcasses_weight'],
"free_bars_carcases_total_wage": finance_info['total_out_carcasses_buying_province_carcasses_price'],
"free_bars_carcases_total_weight": finance_info['total_out_carcasses_buying_province_carcasses_weight'],
"free_bars_out_province_carcases_total_wage": finance_info['total_out_selling_province_carcasses_price'],
"free_bars_out_province_carcases_total_weight": finance_info['total_out_selling_province_carcasses_weight'],
"total_province_live_weight": finance_info['total_province_live_weight'],
"total_province_carcasses_weight": finance_info['total_province_carcasses_weight'],
"province_live_wage_amount": finance_info['province_live_wage_amount'],
"free_buying_live_weight_amount": finance_info['free_buying_live_weight_amount'],
"free_buying_carcesses_weight_amount": finance_info['free_buying_carcesses_weight_amount'],
"free_sell_carcesses_weight_amount": finance_info['free_sell_carcesses_weight_amount'],
"extra_company_amount":finance_info['extra_company_amount'],
"return_total_province_live_weight": finance_info['return_total_province_live_weight'],
"total_return_pure_province_carcasses_price": finance_info['total_return_pure_province_carcasses_price'],
"union_province_kill_request_wage": union_province_kill_request_wage,
"return_union_province_kill_request_wage": return_union_province_kill_request_wage,
"union_free_buying_live_wage": union_free_buying_live_wage,
"union_free_buying_carcasses_wage": union_free_buying_carcasses_wage,
"union_free_sell_carcasses_wage": union_free_sell_carcasses_wage,
"union_total_wage": union_total_wage,
"union_total_paid_wage": union_total_paid_wage,
"union_total_unpaid_wage": union_total_unpaid_wage,
"company_province_kill_request_wage": company_province_kill_request_wage,
"return_company_province_kill_request_wage": return_company_province_kill_request_wage,
"company_free_buying_live_wage": company_free_buying_live_wage,
"company_free_buying_carcasses_wage": company_free_buying_carcasses_wage,
"company_free_sell_carcasses_wage": company_free_sell_carcasses_wage,
"company_total_wage": company_total_wage,
"company_total_paid_wage": company_total_paid_wage,
"company_total_unpaid_wage": company_total_unpaid_wage,
"guilds_province_kill_request_wage": guilds_province_kill_request_wage,
"return_guilds_province_kill_request_wage": return_guilds_province_kill_request_wage,
"guilds_free_buying_live_wage": guilds_free_buying_live_wage,
"guilds_free_buying_carcasses_wage": guilds_free_buying_carcasses_wage,
"guilds_free_sell_carcasses_wage": guilds_free_sell_carcasses_wage,
"guilds_total_wage": guilds_total_wage,
"guilds_total_paid_wage": guilds_total_paid_wage,
"guilds_total_unpaid_wage": guilds_total_unpaid_wage,
"other_province_kill_request_wage": other_province_kill_request_wage,
"return_other_province_kill_request_wage": return_other_province_kill_request_wage,
"other_free_buying_live_wage": other_free_buying_live_wage,
"other_free_buying_carcasses_wage": other_free_buying_carcasses_wage,
"other_free_sell_carcasses_wage": other_free_sell_carcasses_wage,
"other_total_wage": other_total_wage,
"other_total_paid_wage": other_total_paid_wage,
"other_total_unpaid_wage": other_total_unpaid_wage,
}
return result
def get_kill_house_finance_info(kill_house, date1=None, date2=None):
before_total_out_live_buying_province_carcasses_weight = 0
after_total_out_live_buying_province_carcasses_weight = 0

File diff suppressed because it is too large Load Diff