diff --git a/panel/KillHouse/helpers.py b/panel/KillHouse/helpers.py index f5061ad..7a58046 100644 --- a/panel/KillHouse/helpers.py +++ b/panel/KillHouse/helpers.py @@ -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 diff --git a/panel/ProvinceOperator/serializers.py b/panel/ProvinceOperator/serializers.py index fdac27f..12c9109 100644 --- a/panel/ProvinceOperator/serializers.py +++ b/panel/ProvinceOperator/serializers.py @@ -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_total_wage_info from panel.KillHouse.serializers import VetSerializer, ProvinceKillRequestSerializer, \ KillHouseAssignmentInformationSerializer, KillHouseSerializer, KillHouseDailyQuotaSerializer, \ ProvinceKillRequestForAutoAllocationSerializer, KillHouseWareHouseSerializer, KillHouseForProvinceSerializer, \ @@ -77,7 +78,7 @@ from panel.models import ( GuildsGeneralConfigs, StewardAppLogin, StewardRequest, RestrictionCarcassDistribution, AllowRegisterCodeForKillHouseFreeSaleBarInformation, AllowRegisterCodeForStewardFreeSaleBarInformation, LimitationForDirectPurchaseAndBarInformation, WarehouseArchive, SmsRecipient, MarketDailyLimitation, - HatchingArchivePercent, Representative, POSAccessLevel, DispenserInformation + HatchingArchivePercent, Representative, POSAccessLevel, DispenserInformation, KillHousePercentage ) from panel.poultry.helpers import market_daily_limitation_info from panel.poultry.serializers import PoultryRequestSerializer, PoultrySerializer, \ @@ -2897,6 +2898,7 @@ class PoultryOutRequestInternalTransactionSerializer(serializers.ModelSerializer } + # class TotalWageInformationSerializer(serializers.ModelSerializer): # wage_info = serializers.SerializerMethodField('get_wage_info') # @@ -2905,23 +2907,29 @@ class PoultryOutRequestInternalTransactionSerializer(serializers.ModelSerializer # fields = ['key', 'wage_info'] # # def get_wage_info(self, obj): -# +# 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 +# company_before_total_out_live_buying_province_carcasses_price = 0 +# before_total_out_live_buying_province_carcasses_price = 0 +# company_before_total_out_live_buying_province_carcasses_weight = 0 +# extra_company_amount = 0 # total_weight = 0 # total_wage = 0 # total_paid_wage = 0 +# shares_list = [] # total_unpaid_wage = 0 # union_total_weight = 0 # union_total_wage = 0 # union_total_paid_wage = 0 # union_total_unpaid_wage = 0 # union_province_kill_request_total_wage = 0 -# union_poultry_request_out_total_wage = 0 # freezing_union_province_kill_request_total_wage = 0 # union_kill_house_free_live_bar_total_wage = 0 # union_kill_house_free_carcases_bar_total_wage = 0 # union_chain_allocation_total_wage = 0 # union_province_kill_request_total_weight = 0 -# union_poultry_request_out_total_weight = 0 # freezing_union_province_kill_request_total_weight = 0 # union_kill_house_free_live_bar_total_weight = 0 # union_kill_house_free_carcases_bar_total_weight = 0 @@ -2941,8 +2949,6 @@ class PoultryOutRequestInternalTransactionSerializer(serializers.ModelSerializer # company_kill_house_free_live_bar_total_weight = 0 # company_kill_house_free_carcases_bar_total_weight = 0 # company_chain_allocation_total_weight = 0 -# company_poultry_request_out_total_wage = 0 -# company_poultry_request_out_total_weight = 0 # # guilds_total_weight = 0 # guilds_total_wage = 0 @@ -2958,12 +2964,24 @@ class PoultryOutRequestInternalTransactionSerializer(serializers.ModelSerializer # guilds_kill_house_free_live_bar_total_weight = 0 # guilds_kill_house_free_carcases_bar_total_weight = 0 # guilds_chain_allocation_total_weight = 0 -# guilds_poultry_request_out_total_wage = 0 -# guilds_poultry_request_out_total_weight = 0 +# +# other_total_weight = 0 +# other_total_wage = 0 +# other_total_paid_wage = 0 +# other_total_unpaid_wage = 0 +# other_province_kill_request_total_wage = 0 +# freezing_other_province_kill_request_total_wage = 0 +# other_kill_house_free_live_bar_total_wage = 0 +# other_kill_house_free_carcases_bar_total_wage = 0 +# other_chain_allocation_total_wage = 0 +# other_province_kill_request_total_weight = 0 +# freezing_other_province_kill_request_total_weight = 0 +# other_kill_house_free_live_bar_total_weight = 0 +# other_kill_house_free_carcases_bar_total_weight = 0 +# other_chain_allocation_total_weight = 0 +# # province_kill_request_total_wage = 0 # province_kill_request_total_weight = 0 -# poultry_request_out_total_wage = 0 -# poultry_request_out_total_weight = 0 # freezing_province_kill_requests_total_wage = 0 # freezing_province_kill_requests_total_weight = 0 # chain_total_wage = 0 @@ -2972,110 +2990,129 @@ class PoultryOutRequestInternalTransactionSerializer(serializers.ModelSerializer # free_bars_live_total_weight = 0 # free_bars_carcases_total_wage = 0 # free_bars_carcases_total_weight = 0 -# role = self.context.get('request').GET['role'] -# user = SystemUserProfile.objects.get(user=self.context.get('request').user) +# real_free_sale_wage = 0 +# union_real_free_sale_wage = 0 +# company_real_free_sale_wage = 0 +# guilds_real_free_sale_wage = 0 +# other_real_free_sale_wage = 0 +# total_check_wage = 0 +# union_wage_percent = 0 +# company_wage_percent = 0 +# guilds_wage_percent = 0 +# other_wage_percent = 0 +# date1 = None +# date2 = None +# role = None +# if self.context: +# role = self.context.get('request').GET.get('role') +# if self.context.get('request').GET.get('date1'): +# date1 = datetime.strptime(str(self.context.get('request').GET['date1']), +# '%Y-%m-%d').date() +# date2 = datetime.strptime(str(self.context.get('request').GET['date2']), +# '%Y-%m-%d').date() +# +# wage_type = WageType.objects.filter(en_name='province-kill-request').first() +# total_check_wage = wage_type.amount +# percentages_wage_type = PercentageOfWageType.objects.filter(wage_type=wage_type, percent__gt=0, trash=False) +# for percentage_wage_type in percentages_wage_type: +# if percentage_wage_type.share_type.en_name == 'union': +# union_wage_percent = percentage_wage_type.percent / 100 +# elif percentage_wage_type.share_type.en_name == 'company': +# company_wage_percent = percentage_wage_type.percent / 100 +# +# elif percentage_wage_type.share_type.en_name == 'guilds': +# guilds_wage_percent = percentage_wage_type.percent / 100 +# elif percentage_wage_type.share_type.en_name in ['city', 'wallet']: +# pass +# else: +# other_wage_percent = percentage_wage_type.percent / 100 +# total_wage_type = WageType.objects.filter(trash=False) +# province_live_wage_amount = total_wage_type.filter(en_name='province-kill-request', trash=False).first().amount +# free_buying_live_weight_amount = total_wage_type.filter(en_name='live-buy', trash=False).first().amount +# free_buying_carcesses_weight_amount = total_wage_type.filter(en_name='carcasse-buy', trash=False).first().amount +# free_sell_carcesses_weight_amount = total_wage_type.filter(en_name='carcasse-sell', trash=False).first().amount +# out_province_poultry_request_wage_amount = total_wage_type.filter(en_name='poultry-sell-out-province', +# trash=False).first().amount +# # if role == 'KillHouse': +# try: +# user = SystemUserProfile.objects.get(user=self.context.get('request').user) +# except: +# user = SystemUserProfile.objects.get(key=self.context.get('request').GET['key']) # kill_house = KillHouse.objects.filter(kill_house_operator__user=user, trash=False).first() -# province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user=kill_house, -# state__in=('pending', 'accepted'), trash=False, -# return_to_province=False, -# first_car_allocated_quantity=0, -# archive_wage=False, -# ) -# freezing_province_kill_requests = province_kill_requests.filter( -# province_request__poultry_request__freezing=True) +# # if date1: +# # finance_info = get_finance_info(kill_house, date1, date2) +# # slaughter_transactions = InternalTransaction.objects.filter( +# # Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), date__date__gte=date1, +# # date__date__lte=date2, status='completed', +# # trash=False) +# # +# # else: +# # finance_info = get_finance_info(kill_house) +# # slaughter_transactions = InternalTransaction.objects.filter( +# # Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), status='completed', +# # trash=False) +# if date1: +# finance_info = get_finance_info(kill_house, date1, date2) +# if kill_house.killer and kill_house.type == 'public': +# slaughter_transactions = InternalTransaction.objects.filter( +# kill_house=kill_house,parent_kill_house=kill_house, date__date__gte=date1, +# date__date__lte=date2, status='completed', +# trash=False) +# else: +# slaughter_transactions = InternalTransaction.objects.filter( +# Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), date__date__gte=date1, +# date__date__lte=date2, status='completed', +# trash=False) # -# kill_house_requests = KillHouseRequest.objects.filter( -# Q(Q(killhouse_user=kill_house) & Q(killer=kill_house)) | Q( -# Q(killhouse_user=kill_house) & Q(killer__isnull=True)) | Q( -# Q(killhouse_user=kill_house) | Q(killer=kill_house)), archive_wage=False, -# trash=False -# ) -# freezing_kill_house_requests = kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=True) +# else: +# finance_info = get_finance_info(kill_house) +# if kill_house.killer and kill_house.type == 'public': # -# # kill_house_requests = KillHouseRequest.objects.filter( -# # killer=kill_house, archive_wage=False,killer__isnull=False, -# # trash=False -# # ).exclude( -# # province_kill_request__in=province_kill_requests -# # ) -# -# free_bars = KillHouseFreeBarInformation.objects.filter(kill_house=kill_house, archive_wage=False, -# trash=False) -# free_bars_live = free_bars.filter(buy_type='live', trash=False) -# free_bars_carcases = free_bars.filter(buy_type='carcass', trash=False) -# province_kill_requests_total_wage = \ -# province_kill_requests.filter(province_request__poultry_request__freezing=False).aggregate( -# total=Sum('total_wage_amount'))[ -# 'total'] or 0 -# freezing_province_kill_request_total_wage = \ -# freezing_province_kill_requests.aggregate(total=Sum('total_wage_amount'))['total'] or 0 -# -# total_wage += province_kill_requests_total_wage + freezing_province_kill_request_total_wage -# province_kill_requests_total_weight = \ -# province_kill_requests.filter(province_request__poultry_request__freezing=False).aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# freezing_province_kill_request_total_weight = \ -# freezing_province_kill_requests.aggregate(total=Sum('total_killed_weight'))['total'] or 0 -# total_weight += province_kill_requests_total_weight + freezing_province_kill_request_total_weight -# kill_house_reqest_total_wage = \ -# kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum(F('accepted_real_weight') * F('province_kill_request__wage')))[ -# 'total'] or 0 -# freezing_kill_house_reqest_total_wage = \ -# freezing_kill_house_requests.aggregate( -# total=Sum(F('accepted_real_weight') * F('province_kill_request__wage')))[ -# 'total'] or 0 -# total_wage += kill_house_reqest_total_wage + freezing_kill_house_reqest_total_wage -# -# kill_house_reqest_total_weight = kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 -# freezing_kill_house_reqest_total_weight = \ -# freezing_kill_house_requests.aggregate(total=Sum('accepted_real_weight'))[ -# 'total'] or 0 -# -# total_weight += kill_house_reqest_total_weight + freezing_kill_house_reqest_total_weight -# -# free_bars_live_total_wage = free_bars_live.aggregate(total=Sum('total_wage_amount'))[ -# 'total'] or 0 -# total_wage += free_bars_live_total_wage -# free_bars_live_total_weight = free_bars_live.aggregate(total=Sum('live_weight'))[ -# 'total'] or 0 -# total_weight += free_bars_live_total_weight -# free_bars_carcases_total_wage = free_bars_carcases.aggregate(total=Sum('total_wage_amount'))[ -# 'total'] or 0 -# total_wage += free_bars_carcases_total_wage -# free_bars_carcases_total_weight = free_bars_carcases.aggregate(total=Sum('weight_of_carcasses'))[ -# 'total'] or 0 -# total_weight += free_bars_carcases_total_weight -# -# slaughter_transactions = InternalTransaction.objects.filter( -# Q(kill_house=kill_house) | Q(parent_kill_house=kill_house), status='completed', -# trash=False) +# 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 # # return { -# "total_weight": total_weight, -# "total_wage": total_wage, +# "wage_counting_type": wage_counting_type, +# "total_wage": finance_info['total_price'], # "total_paid_wage": total_paid_wage, -# "total_unpaid_wage": total_wage - total_paid_wage, -# "province_kill_requests_total_wage": province_kill_requests_total_wage + kill_house_reqest_total_wage, -# "province_kill_requests_total_weight": province_kill_requests_total_weight + kill_house_reqest_total_weight, -# "freezing_province_kill_requests_total_wage": freezing_province_kill_request_total_wage + freezing_kill_house_reqest_total_wage, -# "freezing_province_kill_requests_total_weight": freezing_province_kill_request_total_weight + freezing_kill_house_reqest_total_weight, -# "free_bars_live_total_wage": free_bars_live_total_wage, -# "free_bars_live_total_weight": free_bars_live_total_weight, -# "free_bars_carcases_total_wage": free_bars_carcases_total_wage, -# "free_bars_carcases_total_weight": free_bars_carcases_total_weight, +# "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": province_live_wage_amount, +# "free_buying_live_weight_amount": free_buying_live_weight_amount, +# "free_buying_carcesses_weight_amount": free_buying_carcesses_weight_amount, +# "free_sell_carcesses_weight_amount": free_sell_carcesses_weight_amount, +# "finance_info": finance_info, +# "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'], # } +# # elif role == 'ChainCompany': +# try: +# user = SystemUserProfile.objects.get(user=self.context.get('request').user) +# except: +# user = SystemUserProfile.objects.get(key=self.context.get('request').GET['key']) # chain_company = ChainCompany.objects.get(user=user, trash=False) # chain_allocations = ChainAllocation.objects.filter(chain_company=chain_company, state='accepted', # trash=False) @@ -3100,767 +3137,456 @@ class PoultryOutRequestInternalTransactionSerializer(serializers.ModelSerializer # "total_unpaid_wage": total_wage - total_paid_wage # } # +# +# +# # else: +# kill_houses = KillHouse.objects.filter(out_province=False, trash=False).order_by('id') +# if date1: # -# if role == 'ProvinceOperator': -# type = 'union_share' -# share_type = 'union_share' -# out_poultry_requests = PoultryRequest.objects.filter(out=True, trash=False, wage_pay=True, -# union_share__gt=0) -# poultry_request_out_total_weight = \ -# out_poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[ -# 'total'] or 0 -# poultry_request_out_total_wage = out_poultry_requests.aggregate( -# total=Sum( -# ((F('quantity') * F('Index_weight')) * F('wage')) * ( -# F('union_share_percent') / 100)))[ -# 'total'] or 0 -# province_kill_requests = ProvinceKillRequest.objects.filter( -# state__in=('pending', 'accepted'), trash=False, -# first_car_allocated_quantity=0, -# return_to_province=False, archive_wage=False, union_share__gt=0) -# freezing_province_kill_requests = province_kill_requests.filter( -# province_request__poultry_request__freezing=True) -# kill_house_requests = KillHouseRequest.objects.filter(trash=False, archive_wage=False, -# province_kill_request__union_share__gt=0) -# freezing_kill_house_requests = kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=True) +# province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, trash=False, +# archive_wage=False, +# return_to_province=False, +# state__in=('pending', 'accepted'), +# kill_request__recive_date__date__gte=date1, +# kill_request__recive_date__date__lte=date2, +# first_car_allocated_quantity=0).order_by( +# 'id') +# return_province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, +# trash=True, return_trash=True, +# archive_wage=False, +# return_to_province=False, +# state__in=('pending', 'accepted'), +# kill_request__recive_date__date__gte=date1, +# kill_request__recive_date__date__lte=date2, +# first_car_allocated_quantity=0).order_by( +# 'id') +# kill_house_requests = KillHouseRequest.objects.filter( +# Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( +# Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( +# Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, +# kill_request__recive_date__date__gte=date1, kill_request__recive_date__date__lte=date2, +# trash=False, calculate_status=True +# ) +# return_kill_house_requests = KillHouseRequest.objects.filter( +# Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( +# Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( +# Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, +# kill_request__recive_date__date__gte=date1, kill_request__recive_date__date__lte=date2, +# trash=True, return_trash=True, calculate_status=True +# ) +# kill_house_free_bar_info = KillHouseFreeBarInformation.objects.filter(kill_house__in=kill_houses, +# archive_wage=False, +# calculate_status=True, +# create_date__date__gte=date1, +# create_date__date__lte=date2, +# trash=False) +# kill_house_free_sale_bar_info = KillHouseFreeSaleBarInformation.objects.filter( +# kill_house__in=kill_houses, +# archive_wage=False, calculate_status=True, date__date__gte=date1, date__date__lte=date2, +# trash=False) # -# chain_allocations = ChainAllocation.objects.filter(union_share__gt=0, state='accepted', trash=False) -# free_bars = KillHouseFreeBarInformation.objects.filter(union_share__gt=0, archive_wage=False, -# trash=False) +# slaughter_transactions = InternalTransaction.objects.filter( +# kill_house__in=kill_houses, status='completed', date__date__gte=date1, date__date__lte=date2, +# trash=False) +# poultry_transactions = InternalTransaction.objects.filter( +# poultry__isnull=False, status='completed', date__date__gte=date1, date__date__lte=date2, +# trash=False) # -# province_kill_requests_total_weight = \ -# province_kill_requests.aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# freezing_province_kill_requests_total_weight = \ -# freezing_province_kill_requests.aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# province_kill_requests_total_weight += \ -# kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 +# poultry_requests = PoultryRequest.objects.filter(trash=False, state_process__in=('pending', 'accepted'), +# province_state__in=('pending', 'accepted'), out=True, +# out_province_request_cancel=False, +# temporary_trash=False, send_date__date__gte=date1, +# send_date__date__lte=date2, +# wage_pay=True, has_wage=True, +# temporary_deleted=False) +# difference_requests = BarDifferenceRequest.objects.filter(kill_house__in=kill_houses, trash=False, +# create_date__date__gte=date1, +# create_date__date__lte=date2, +# state='accepted') +# else: +# province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, trash=False, +# archive_wage=False, +# return_to_province=False, +# state__in=('pending', 'accepted'), +# first_car_allocated_quantity=0).order_by( +# 'id') +# return_province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, +# trash=True, return_trash=True, +# archive_wage=False, +# return_to_province=False, +# state__in=('pending', 'accepted'), +# first_car_allocated_quantity=0).order_by( +# 'id') +# kill_house_requests = KillHouseRequest.objects.filter( +# Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( +# Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( +# Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, +# trash=False, calculate_status=True +# ) +# return_kill_house_requests = KillHouseRequest.objects.filter( +# Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( +# Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( +# Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, +# trash=True, return_trash=True, calculate_status=True +# ) +# kill_house_free_bar_info = KillHouseFreeBarInformation.objects.filter(kill_house__in=kill_houses, +# archive_wage=False, +# calculate_status=True, +# trash=False) +# kill_house_free_sale_bar_info = KillHouseFreeSaleBarInformation.objects.filter( +# kill_house__in=kill_houses, +# archive_wage=False, calculate_status=True, +# trash=False) # -# freezing_province_kill_requests_total_weight += \ -# freezing_kill_house_requests.aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 +# slaughter_transactions = InternalTransaction.objects.filter( +# kill_house__in=kill_houses, status='completed', +# trash=False) +# poultry_transactions = InternalTransaction.objects.filter( +# poultry__isnull=False, status='completed', +# trash=False) # -# total_weight += province_kill_requests_total_weight + freezing_province_kill_requests_total_weight + poultry_request_out_total_weight +# poultry_requests = PoultryRequest.objects.filter(trash=False, state_process__in=('pending', 'accepted'), +# province_state__in=('pending', 'accepted'), out=True, +# out_province_request_cancel=False, +# temporary_trash=False, +# wage_pay=True, has_wage=True, +# temporary_deleted=False) +# difference_requests = BarDifferenceRequest.objects.filter(kill_house__in=kill_houses, trash=False, +# state='accepted') # -# province_kill_requests_total_wage = \ -# province_kill_requests.filter( -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('union_share'))[ -# 'total'] or 0 -# province_kill_requests_total_wage += \ -# kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__union_share_percent') / 100)))[ -# 'total'] or 0 -# -# freezing_province_kill_requests_total_wage = \ -# freezing_province_kill_requests.aggregate(total=Sum('union_share'))[ -# 'total'] or 0 -# freezing_province_kill_requests_total_wage += \ -# freezing_kill_house_requests.aggregate(total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__union_share_percent') / 100)))[ -# 'total'] or 0 -# total_wage += province_kill_requests_total_wage + freezing_province_kill_requests_total_wage + poultry_request_out_total_wage -# -# free_bars_live = free_bars.filter(buy_type='live', trash=False) -# free_bars_carcases = free_bars.filter(buy_type='carcass', trash=False) -# -# chain_allocations_total_wage = chain_allocations.aggregate(total=Sum(type))[ -# 'total'] or 0 -# total_wage += chain_allocations_total_wage -# chain_allocations_total_weight = chain_allocations.aggregate(total=Sum('weight'))[ -# 'total'] or 0 -# total_weight += chain_allocations_total_weight -# free_bars_live_total_wage = free_bars_live.aggregate(total=Sum(type))[ -# 'total'] or 0 -# total_wage += free_bars_live_total_wage -# free_bars_live_total_weight = free_bars_live.aggregate(total=Sum('live_weight'))[ -# 'total'] or 0 -# total_weight += free_bars_live_total_weight -# free_bars_carcases_total_wage = free_bars_carcases.aggregate(total=Sum(type))[ +# out_province_poultry_request_weight = \ +# poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[ +# 'total'] or 0 +# out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('total_wage_amount'))[ # 'total'] or 0 -# total_wage += free_bars_carcases_total_wage -# free_bars_carcases_total_weight = free_bars_carcases.aggregate(total=Sum('weight_of_carcasses'))[ -# 'total'] or 0 -# total_weight += free_bars_carcases_total_weight -# slaughter_transactions = InternalTransaction.objects.filter(payer_type='kill_house', status='completed', -# union_share__gt=0, -# trash=False) +# union_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('union_share'))[ +# 'total'] or 0 +# company_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('company_share'))[ +# 'total'] or 0 +# guilds_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('guilds_share'))[ +# 'total'] or 0 +# other_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('other_share'))[ +# 'total'] or 0 # -# total_paid_wage += slaughter_transactions.aggregate(total=Sum(share_type))[ -# 'total'] or 0 -# chain_company_transactions = InternalTransaction.objects.filter(payer_type='chain_company', -# status='completed', union_share__gt=0, -# trash=False) -# total_paid_wage += chain_company_transactions.aggregate(total=Sum(share_type))[ -# 'total'] or 0 +# off = kill_houses.aggregate(total=Sum('off'))[ +# 'total'] or 0 # +# total_paid_wage = slaughter_transactions.aggregate(total=Sum('amount'))[ +# 'total'] or 0 +# total_paid_wage += poultry_transactions.aggregate(total=Sum('amount'))[ +# 'total'] or 0 # +# total_province_live_weight = province_kill_requests.aggregate(total=Sum('total_killed_weight'))[ +# 'total'] or 0 +# total_province_live_weight += kill_house_requests.aggregate(total=Sum('accepted_real_weight'))['total'] or 0 +# # total_out_selling_province_carcasses_weight = \ +# # kill_house_free_sale_bar_info.aggregate(total=Sum('real_weight_of_carcasses'))['total'] or 0 +# # total_out_selling_province_quarantine_carcasses_weight = \ +# # kill_house_free_sale_bar_info.aggregate(total=Sum('quarantine_weight_of_carcasses'))['total'] or 0 # -# elif role == 'Guilds': -# type = 'guilds_share' -# share_type = 'guilds_share' -# out_poultry_requests = PoultryRequest.objects.filter(out=True, trash=False, wage_pay=True, -# guilds_share__gt=0) -# poultry_request_out_total_weight = \ -# out_poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[ -# 'total'] or 0 -# poultry_request_out_total_wage = out_poultry_requests.aggregate( -# total=Sum( -# ((F('quantity') * F('Index_weight')) * F('wage')) * ( -# F('guilds_share_percent') / 100)))[ -# 'total'] or 0 -# province_kill_requests = ProvinceKillRequest.objects.filter( -# state__in=('pending', 'accepted'), trash=False, -# first_car_allocated_quantity=0, +# # sum_quarantine_carcasses_weight = \ +# # kill_house_free_sale_bar_info.filter(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() +# # ) +# # ) +# # ) +# # total_out_selling_province_quarantine_carcasses_weight = sum_quarantine_carcasses_weight[ +# # 'total_weight'] or 0 # -# return_to_province=False, archive_wage=False, guilds_share__gt=0) -# freezing_province_kill_requests = province_kill_requests.filter( -# province_request__poultry_request__freezing=True) +# total_province_live_weight += \ +# difference_requests.aggregate(total=Sum('weight'))['total'] or 0 +# difference_requests_weight = \ +# difference_requests.aggregate(total=Sum('weight'))['total'] or 0 +# return_total_province_live_weight = \ +# return_province_kill_requests.aggregate(total=Sum('total_killed_weight'))[ +# 'total'] or 0 +# return_total_province_live_weight += \ +# return_kill_house_requests.aggregate(total=Sum('accepted_real_weight'))['total'] or 0 +# 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 # -# kill_house_requests = KillHouseRequest.objects.filter(trash=False, archive_wage=False, -# province_kill_request__guilds_share__gt=0) -# freezing_kill_house_requests = kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=True) +# total_out_selling_province_carcasses_weight += new_out_selling # -# chain_allocations = ChainAllocation.objects.filter(guilds_share__gt=0, state='accepted', trash=False) -# free_bars = KillHouseFreeBarInformation.objects.filter(guilds_share__gt=0, archive_wage=False, -# trash=False) +# if wage_counting_type == 'live': +# total_province_carcasses_weight = total_province_live_weight # -# province_kill_requests_total_weight = \ -# province_kill_requests.filter( -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# freezing_province_kill_requests_total_weight = \ -# freezing_province_kill_requests.aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# province_kill_requests_total_weight += \ -# kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 +# total_pure_province_carcasses_weight = total_province_carcasses_weight +# else: +# return_total_province_live_weight = int(return_total_province_live_weight * 0.75) +# total_province_carcasses_weight = total_province_live_weight * 0.75 +# difference_requests_weight = difference_requests_weight * 0.75 # -# freezing_province_kill_requests_total_weight += \ -# freezing_kill_house_requests.aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 +# total_out_carcasses_buying_for_pure_province_carcasses_weight = \ +# kill_house_free_bar_info.aggregate(total=Sum('weight_of_carcasses'))['total'] or 0 +# if date1: +# total_pure_province_carcasses_weight = total_province_carcasses_weight - get_difference_carcasses_weight( +# kill_houses, date1, date2) +# else: +# total_pure_province_carcasses_weight = total_province_carcasses_weight - get_difference_carcasses_weight( +# kill_houses) +# total_out_live_buying_province_carcasses_weight = \ +# kill_house_free_bar_info.filter(buy_type='live').aggregate(total=Sum('live_weight'))['total'] or 0 +# real_total_out_live_buying_province_carcasses_weight = total_out_live_buying_province_carcasses_weight +# 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) # -# total_weight += province_kill_requests_total_weight + freezing_province_kill_requests_total_weight + poultry_request_out_total_weight +# 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 # -# province_kill_requests_total_wage = \ -# province_kill_requests.filter( -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('union_share'))[ -# 'total'] or 0 -# province_kill_requests_total_wage += \ -# kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__guilds_share_percent') / 100)))[ -# 'total'] or 0 +# 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 # -# freezing_province_kill_requests_total_wage = \ -# freezing_province_kill_requests.aggregate(total=Sum('guilds_share'))[ -# 'total'] or 0 -# freezing_province_kill_requests_total_wage += \ -# freezing_kill_house_requests.aggregate(total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__guilds_share_percent') / 100)))[ -# 'total'] or 0 -# total_wage += province_kill_requests_total_wage + freezing_province_kill_requests_total_wage + poultry_request_out_total_wage +# else: +# extra_company_amount = int( +# after_total_out_live_buying_province_carcasses_weight * extra_company_amount) # -# free_bars_live = free_bars.filter(buy_type='live', trash=False) -# free_bars_carcases = free_bars.filter(buy_type='carcass', trash=False) -# -# chain_allocations_total_wage = chain_allocations.aggregate(total=Sum(type))[ -# 'total'] or 0 -# total_wage += chain_allocations_total_wage -# chain_allocations_total_weight = chain_allocations.aggregate(total=Sum('weight'))[ -# 'total'] or 0 -# total_weight += chain_allocations_total_weight -# free_bars_live_total_wage = free_bars_live.aggregate(total=Sum(type))[ -# 'total'] or 0 -# total_wage += free_bars_live_total_wage -# free_bars_live_total_weight = free_bars_live.aggregate(total=Sum('live_weight'))[ -# 'total'] or 0 -# total_weight += free_bars_live_total_weight -# free_bars_carcases_total_wage = free_bars_carcases.aggregate(total=Sum(type))[ -# 'total'] or 0 -# total_wage += free_bars_carcases_total_wage -# free_bars_carcases_total_weight = free_bars_carcases.aggregate(total=Sum('weight_of_carcasses'))[ -# 'total'] or 0 -# total_weight += free_bars_carcases_total_weight -# slaughter_transactions = InternalTransaction.objects.filter(payer_type='kill_house', status='completed', -# guilds_share__gt=0, -# trash=False) -# -# total_paid_wage += slaughter_transactions.aggregate(total=Sum(share_type))[ -# 'total'] or 0 -# chain_company_transactions = InternalTransaction.objects.filter(payer_type='chain_company', -# status='completed', guilds_share__gt=0, -# trash=False) -# total_paid_wage += chain_company_transactions.aggregate(total=Sum(share_type))[ -# 'total'] or 0 -# -# -# elif role == 'Company': -# type = 'company_share' -# share_type = 'company_share' -# out_poultry_requests = PoultryRequest.objects.filter(out=True, trash=False, wage_pay=True, -# company_share__gt=0) -# poultry_request_out_total_weight = \ -# out_poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[ -# 'total'] or 0 -# poultry_request_out_total_wage = out_poultry_requests.aggregate( -# total=Sum( -# ((F('quantity') * F('Index_weight')) * F('wage')) * ( -# F('company_share_percent') / 100)))[ -# 'total'] or 0 -# province_kill_requests = ProvinceKillRequest.objects.filter( -# state__in=('pending', 'accepted'), trash=False, -# first_car_allocated_quantity=0, -# return_to_province=False, archive_wage=False, company_share__gt=0) -# freezing_province_kill_requests = province_kill_requests.filter( -# province_request__poultry_request__freezing=True) -# -# kill_house_requests = KillHouseRequest.objects.filter(trash=False, archive_wage=False, -# province_kill_request__company_share__gt=0) -# freezing_kill_house_requests = kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=True) -# -# chain_allocations = ChainAllocation.objects.filter(company_share__gt=0, state='accepted', trash=False) -# free_bars = KillHouseFreeBarInformation.objects.filter(company_share__gt=0, archive_wage=False, -# trash=False) -# -# province_kill_requests_total_weight = \ -# province_kill_requests.filter( -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# freezing_province_kill_requests_total_weight = \ -# freezing_province_kill_requests.aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# province_kill_requests_total_weight += \ -# kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 -# -# freezing_province_kill_requests_total_weight += \ -# freezing_kill_house_requests.aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 -# -# total_weight += province_kill_requests_total_weight + freezing_province_kill_requests_total_weight + poultry_request_out_total_weight -# -# province_kill_requests_total_wage = \ -# province_kill_requests.filter( -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('union_share'))[ -# 'total'] or 0 -# province_kill_requests_total_wage += \ -# kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__company_share_percent') / 100)))[ -# 'total'] or 0 -# -# freezing_province_kill_requests_total_wage = \ -# freezing_province_kill_requests.aggregate(total=Sum('company_share'))[ -# 'total'] or 0 -# freezing_province_kill_requests_total_wage += \ -# freezing_kill_house_requests.aggregate(total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__company_share_percent') / 100)))[ -# 'total'] or 0 -# total_wage += province_kill_requests_total_wage + freezing_province_kill_requests_total_wage + poultry_request_out_total_wage -# -# free_bars_live = free_bars.filter(buy_type='live', trash=False) -# free_bars_carcases = free_bars.filter(buy_type='carcass', trash=False) -# -# chain_allocations_total_wage = chain_allocations.aggregate(total=Sum(type))[ -# 'total'] or 0 -# total_wage += chain_allocations_total_wage -# chain_allocations_total_weight = chain_allocations.aggregate(total=Sum('weight'))[ -# 'total'] or 0 -# total_weight += chain_allocations_total_weight -# free_bars_live_total_wage = free_bars_live.aggregate(total=Sum(type))[ -# 'total'] or 0 -# total_wage += free_bars_live_total_wage -# free_bars_live_total_weight = free_bars_live.aggregate(total=Sum('live_weight'))[ -# 'total'] or 0 -# total_weight += free_bars_live_total_weight -# free_bars_carcases_total_wage = free_bars_carcases.aggregate(total=Sum(type))[ -# 'total'] or 0 -# total_wage += free_bars_carcases_total_wage -# free_bars_carcases_total_weight = free_bars_carcases.aggregate(total=Sum('weight_of_carcasses'))[ -# 'total'] or 0 -# total_weight += free_bars_carcases_total_weight -# slaughter_transactions = InternalTransaction.objects.filter(payer_type='kill_house', status='completed', -# company_share__gt=0, -# trash=False) -# -# total_paid_wage += slaughter_transactions.aggregate(total=Sum(share_type))[ -# 'total'] or 0 -# chain_company_transactions = InternalTransaction.objects.filter(payer_type='chain_company', -# status='completed', company_share__gt=0, -# trash=False) -# total_paid_wage += chain_company_transactions.aggregate(total=Sum(share_type))[ -# 'total'] or 0 +# 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 +# company_before_total_out_live_buying_province_carcasses_weight = before_total_out_live_buying_province_carcasses_weight # # else: -# type = 'total_wage_amount' -# share_type = 'amount' -# out_poultry_requests = PoultryRequest.objects.filter(out=True, trash=False, wage_pay=True) -# poultry_request_out_total_weight = \ -# out_poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[ -# 'total'] or 0 -# poultry_request_out_total_wage = out_poultry_requests.aggregate( -# total=Sum( -# (F('quantity') * F('Index_weight')) * F('wage')))[ -# 'total'] or 0 -# province_kill_requests = ProvinceKillRequest.objects.filter( -# state__in=('pending', 'accepted'), trash=False, archive_wage=False, -# first_car_allocated_quantity=0, -# return_to_province=False) -# freezing_province_kill_requests = province_kill_requests.filter( -# province_request__poultry_request__freezing=True) +# 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 # -# kill_house_requests = KillHouseRequest.objects.filter(trash=False, archive_wage=False) -# freezing_kill_house_requests = kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=True) -# -# chain_allocations = ChainAllocation.objects.filter(trash=False, state='accepted') -# free_bars = KillHouseFreeBarInformation.objects.filter(archive_wage=False, trash=False) -# total_slaughter_transactions = InternalTransaction.objects.filter(payer_type='kill_house', -# status='completed', -# trash=False) -# total_chain_company_transactions = InternalTransaction.objects.filter(payer_type='chain_company', -# status='completed', trash=False) -# -# province_kill_requests_total_weight = \ -# province_kill_requests.filter( -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# freezing_province_kill_requests_total_weight = \ -# freezing_province_kill_requests.aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# province_kill_requests_total_weight += \ -# kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 -# -# freezing_province_kill_requests_total_weight += \ -# freezing_kill_house_requests.aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 -# -# total_weight += province_kill_requests_total_weight + freezing_province_kill_requests_total_weight + poultry_request_out_total_weight -# -# province_kill_requests_total_wage = \ -# province_kill_requests.filter( -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('union_share'))[ -# 'total'] or 0 -# province_kill_requests_total_wage += \ -# kill_house_requests.filter( -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum(F('accepted_real_weight') * F('province_kill_request__wage')))[ -# 'total'] or 0 -# -# freezing_province_kill_requests_total_wage = \ -# freezing_province_kill_requests.aggregate(total=Sum(type))[ -# 'total'] or 0 -# freezing_province_kill_requests_total_wage += \ -# freezing_kill_house_requests.aggregate( -# total=Sum(F('accepted_real_weight') * F('province_kill_request__wage')))[ -# 'total'] or 0 -# total_wage += province_kill_requests_total_wage + freezing_province_kill_requests_total_wage + poultry_request_out_total_wage -# -# free_bars_live = free_bars.filter(buy_type='live', trash=False) -# free_bars_carcases = free_bars.filter(buy_type='carcass', trash=False) -# -# chain_allocations_total_wage = chain_allocations.aggregate(total=Sum(type))[ -# 'total'] or 0 -# total_wage += chain_allocations_total_wage -# chain_allocations_total_weight = chain_allocations.aggregate(total=Sum('weight'))[ -# 'total'] or 0 -# total_weight += chain_allocations_total_weight -# free_bars_live_total_wage = free_bars_live.aggregate(total=Sum(type))[ -# 'total'] or 0 -# total_wage += free_bars_live_total_wage -# free_bars_live_total_weight = free_bars_live.aggregate(total=Sum('live_weight'))[ -# 'total'] or 0 -# total_weight += free_bars_live_total_weight -# free_bars_carcases_total_wage = free_bars_carcases.aggregate(total=Sum(type))[ -# 'total'] or 0 -# total_wage += free_bars_carcases_total_wage -# free_bars_carcases_total_weight = free_bars_carcases.aggregate(total=Sum('weight_of_carcasses'))[ -# 'total'] or 0 -# total_weight += free_bars_carcases_total_weight -# slaughter_transactions = InternalTransaction.objects.filter(payer_type='kill_house', status='completed', -# trash=False) -# -# total_paid_wage += slaughter_transactions.aggregate(total=Sum(share_type))[ -# 'total'] or 0 -# chain_company_transactions = InternalTransaction.objects.filter(payer_type='chain_company', -# status='completed', -# trash=False) -# total_paid_wage += chain_company_transactions.aggregate(total=Sum(share_type))[ -# 'total'] or 0 -# -# union_poultry_request_out_total_weight = \ -# out_poultry_requests.filter(union_share__gt=0).aggregate(total=Sum(F('quantity') * F('Index_weight')))[ +# 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 -# union_poultry_request_out_total_wage = out_poultry_requests.aggregate( -# total=Sum( -# ((F('quantity') * F('Index_weight')) * F('wage')) * ( -# F('union_share_percent') / 100)))[ -# 'total'] or 0 +# total_pure_province_carcasses_price = total_pure_province_carcasses_weight * province_live_wage_amount +# difference_requests_price = difference_requests_weight * province_live_wage_amount +# total_return_pure_province_carcasses_price = return_total_province_live_weight * province_live_wage_amount +# total_out_selling_province_carcasses_price = total_out_selling_province_carcasses_weight * free_sell_carcesses_weight_amount # -# union_province_kill_request_total_weight = \ -# province_kill_requests.filter(union_share__gt=0, -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# freezing_union_province_kill_request_total_weight = \ -# freezing_province_kill_requests.filter(union_share__gt=0).aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# union_province_kill_request_total_weight += \ -# kill_house_requests.filter(province_kill_request__union_share__gt=0, -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 +# if new_out_selling_count_wage: +# total_out_live_buying_province_carcasses_price = int( +# (before_total_out_live_buying_province_carcasses_weight * before_out_buying_count_wage_amount) + ( +# after_total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount)) # -# freezing_union_province_kill_request_total_weight += \ -# freezing_kill_house_requests.filter(province_kill_request__union_share__gt=0).aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 +# before_total_out_live_buying_province_carcasses_price = before_total_out_live_buying_province_carcasses_weight * before_out_buying_count_wage_amount +# else: +# total_out_live_buying_province_carcasses_price = total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount # -# union_province_kill_request_total_wage = \ -# province_kill_requests.filter(union_share__gt=0, -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('union_share'))[ -# 'total'] or 0 -# union_province_kill_request_total_wage += \ -# kill_house_requests.filter(province_kill_request__union_share__gt=0, -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__union_share_percent') / 100)))[ -# 'total'] or 0 +# # total_out_live_buying_province_carcasses_price = total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount +# total_out_carcasses_buying_province_carcasses_price = total_out_carcasses_buying_province_carcasses_weight * free_buying_carcesses_weight_amount +# total_price = total_pure_province_carcasses_price + total_out_selling_province_carcasses_price + total_out_live_buying_province_carcasses_price + total_out_carcasses_buying_province_carcasses_price + out_province_poultry_request_wage + extra_company_amount + total_return_pure_province_carcasses_price # -# freezing_union_province_kill_request_total_wage = \ -# freezing_province_kill_requests.filter(union_share__gt=0).aggregate(total=Sum('union_share'))[ -# 'total'] or 0 -# freezing_union_province_kill_request_total_wage += \ -# freezing_kill_house_requests.filter(province_kill_request__union_share__gt=0).aggregate(total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__union_share_percent') / 100)))[ -# 'total'] or 0 -# union_chain_allocation_total_weight = \ -# chain_allocations.filter(union_share__gt=0).aggregate(total=Sum('weight'))[ -# 'total'] or 0 -# union_chain_allocation_total_wage = \ -# chain_allocations.filter(union_share__gt=0).aggregate(total=Sum('union_share'))[ -# 'total'] or 0 -# union_kill_house_free_live_bar_total_weight = \ -# free_bars.filter(buy_type='live', union_share__gt=0).aggregate(total=Sum('live_weight'))[ -# 'total'] or 0 -# union_kill_house_free_live_bar_total_wage = \ -# free_bars.filter(buy_type='live', union_share__gt=0).aggregate(total=Sum('union_share'))[ -# 'total'] or 0 +# 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_kill_house_free_carcases_bar_total_weight = \ -# free_bars.filter(buy_type='carcass', union_share__gt=0).aggregate(total=Sum('weight_of_carcasses'))[ -# 'total'] or 0 -# union_kill_house_free_carcases_bar_total_wage = \ -# free_bars.filter(buy_type='carcass', union_share__gt=0).aggregate(total=Sum('union_share'))[ -# 'total'] or 0 -# union_total_paid_wage += \ -# total_slaughter_transactions.filter(union_share__gt=0).aggregate(total=Sum('union_share'))[ -# 'total'] or 0 -# union_total_paid_wage += \ -# total_chain_company_transactions.filter(union_share__gt=0).aggregate(total=Sum('union_share'))[ -# 'total'] or 0 -# union_total_weight = union_province_kill_request_total_weight + freezing_union_province_kill_request_total_weight + union_chain_allocation_total_weight + union_kill_house_free_live_bar_total_weight + union_kill_house_free_carcases_bar_total_weight + union_poultry_request_out_total_weight -# union_total_wage = union_province_kill_request_total_wage + freezing_union_province_kill_request_total_wage + union_chain_allocation_total_wage + union_kill_house_free_live_bar_total_wage + union_kill_house_free_carcases_bar_total_wage -# union_total_unpaid_wage = union_total_wage - ( -# union_total_paid_wage + union_poultry_request_out_total_wage) +# 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 # -# company_poultry_request_out_total_weight = \ -# out_poultry_requests.filter(company_share__gt=0).aggregate( -# total=Sum(F('quantity') * F('Index_weight')))[ -# 'total'] or 0 -# company_poultry_request_out_total_wage = out_poultry_requests.filter(company_share__gt=0).aggregate( -# total=Sum( -# ((F('quantity') * F('Index_weight')) * F('wage')) * ( -# F('company_share_percent') / 100)))[ -# 'total'] or 0 +# 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 # -# company_province_kill_request_total_weight = \ -# province_kill_requests.filter(company_share__gt=0, -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# company_province_kill_request_total_weight += \ -# kill_house_requests.filter(province_kill_request__company_share__gt=0, -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 -# freezing_company_province_kill_request_total_weight = \ -# freezing_province_kill_requests.filter(company_share__gt=0).aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# freezing_company_province_kill_request_total_weight += \ -# freezing_kill_house_requests.filter(province_kill_request__company_share__gt=0).aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 -# company_province_kill_request_total_wage = \ -# province_kill_requests.filter(company_share__gt=0, -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('company_share'))[ -# 'total'] or 0 -# company_province_kill_request_total_wage += \ -# kill_house_requests.filter(province_kill_request__company_share__gt=0, -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__company_share_percent') / 100)))[ -# 'total'] or 0 -# freezing_company_province_kill_request_total_wage = \ -# freezing_province_kill_requests.filter(company_share__gt=0).aggregate(total=Sum('company_share'))[ -# 'total'] or 0 -# freezing_company_province_kill_request_total_wage += \ -# freezing_kill_house_requests.filter(province_kill_request__company_share__gt=0).aggregate(total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__company_share_percent') / 100)))[ -# 'total'] or 0 -# company_chain_allocation_total_weight = \ -# chain_allocations.filter(company_share__gt=0).aggregate(total=Sum('weight'))[ -# 'total'] or 0 -# company_chain_allocation_total_wage = \ -# chain_allocations.filter(company_share__gt=0).aggregate(total=Sum('company_share'))[ -# 'total'] or 0 -# company_kill_house_free_live_bar_total_weight = \ -# free_bars.filter(buy_type='live', company_share__gt=0).aggregate(total=Sum('live_weight'))[ -# 'total'] or 0 -# company_kill_house_free_live_bar_total_wage = \ -# free_bars.filter(buy_type='live', company_share__gt=0).aggregate(total=Sum('company_share'))[ -# 'total'] or 0 +# union_province_kill_request_wage = total_pure_province_carcasses_price * union_province_kill_request_percent +# return_union_province_kill_request_wage = total_return_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 + union_out_province_poultry_request_wage + return_union_province_kill_request_wage +# union_total_paid_wage = slaughter_transactions.aggregate(total=Sum('union_share'))['total'] or 0 +# union_total_paid_wage += poultry_transactions.aggregate(total=Sum('union_share'))['total'] or 0 +# union_total_unpaid_wage = union_total_wage - union_total_paid_wage # -# company_kill_house_free_carcases_bar_total_weight = \ -# free_bars.filter(buy_type='carcass', company_share__gt=0).aggregate( -# total=Sum('weight_of_carcasses'))[ -# 'total'] or 0 -# company_kill_house_free_carcases_bar_total_wage = \ -# free_bars.filter(buy_type='carcass', company_share__gt=0).aggregate(total=Sum('company_share'))[ -# 'total'] or 0 -# company_total_paid_wage += \ -# total_slaughter_transactions.filter(company_share__gt=0).aggregate(total=Sum('company_share'))[ -# 'total'] or 0 -# company_total_paid_wage += \ -# total_chain_company_transactions.filter(company_share__gt=0).aggregate(total=Sum('company_share'))[ -# 'total'] or 0 -# company_total_weight = company_province_kill_request_total_weight + freezing_company_province_kill_request_total_weight + company_chain_allocation_total_weight + company_kill_house_free_live_bar_total_weight + company_kill_house_free_carcases_bar_total_weight + company_poultry_request_out_total_weight -# company_total_wage = company_province_kill_request_total_wage + freezing_company_province_kill_request_total_wage + company_chain_allocation_total_wage + company_kill_house_free_live_bar_total_wage + company_kill_house_free_carcases_bar_total_wage -# company_total_unpaid_wage = company_total_wage - (company_total_paid_wage + company_poultry_request_out_total_wage) +# shares_list.append({ +# "name": "اتحادیه", +# "out_province_poultry_request_wage": union_out_province_poultry_request_wage, +# "province_kill_request_wage": union_province_kill_request_wage, +# "return_province_kill_request_wage": return_union_province_kill_request_wage, +# "free_buying_live_wage": union_free_buying_live_wage, +# "free_buying_carcasses_wage": union_free_buying_carcasses_wage, +# "free_sell_carcasses_wage": union_free_sell_carcasses_wage, +# "total_wage": union_total_wage, +# "total_paid_wage": union_total_paid_wage, +# "total_unpaid_wage": union_total_unpaid_wage, # +# }) # -# guilds_poultry_request_out_total_weight = \ -# out_poultry_requests.filter(guilds_share__gt=0).aggregate( -# total=Sum(F('quantity') * F('Index_weight')))[ -# 'total'] or 0 -# guilds_poultry_request_out_total_wage = out_poultry_requests.filter(guilds_share__gt=0).aggregate( -# total=Sum( -# ((F('quantity') * F('Index_weight')) * F('wage')) * ( -# F('guilds_share_percent') / 100)))[ -# 'total'] or 0 +# 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 = total_return_pure_province_carcasses_price * guilds_province_kill_request_percent +# other_return_province_kill_request_wage = total_return_pure_province_carcasses_price * other_province_kill_request_percent # +# 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 = ( +# total_return_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 + company_out_province_poultry_request_wage + return_company_province_kill_request_wage +# company_total_paid_wage = slaughter_transactions.aggregate(total=Sum('company_share'))['total'] or 0 +# company_total_paid_wage += poultry_transactions.aggregate(total=Sum('company_share'))['total'] or 0 +# # company_total_pure_paid_wage = company_total_paid_wage - (company_total_paid_wage * 0.08)) +# company_total_unpaid_wage = company_total_wage - company_total_paid_wage # -# guilds_province_kill_request_total_weight = \ -# province_kill_requests.filter(guilds_share__gt=0, -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# guilds_province_kill_request_total_weight += \ -# kill_house_requests.filter(province_kill_request__guilds_share__gt=0, -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 +# shares_list.append({ +# "name": "شرکت", +# "out_province_poultry_request_wage": company_out_province_poultry_request_wage, +# "province_kill_request_wage": company_province_kill_request_wage, +# "return_province_kill_request_wage": return_company_province_kill_request_wage, +# "free_buying_live_wage": company_free_buying_live_wage, +# "free_buying_carcasses_wage": company_free_buying_carcasses_wage, +# "free_sell_carcasses_wage": company_free_sell_carcasses_wage, +# "total_wage": company_total_wage, +# "total_paid_wage": company_total_paid_wage, +# "total_unpaid_wage": company_total_unpaid_wage, # -# freezing_guilds_province_kill_request_total_weight = \ -# freezing_province_kill_requests.filter(guilds_share__gt=0).aggregate( -# total=Sum('total_killed_weight'))[ -# 'total'] or 0 -# freezing_guilds_province_kill_request_total_weight += \ -# freezing_kill_house_requests.filter(province_kill_request__guilds_share__gt=0).aggregate( -# total=Sum('accepted_real_weight'))[ -# 'total'] or 0 -# guilds_province_kill_request_total_wage = \ -# province_kill_requests.filter(guilds_share__gt=0, -# province_request__poultry_request__freezing=False).aggregate( -# total=Sum('guilds_share'))[ -# 'total'] or 0 -# guilds_province_kill_request_total_wage += \ -# kill_house_requests.filter(province_kill_request__guilds_share__gt=0, -# province_kill_request__province_request__poultry_request__freezing=False).aggregate( -# total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__guilds_share_percent') / 100)))[ -# 'total'] or 0 -# freezing_guilds_province_kill_request_total_wage = \ -# freezing_province_kill_requests.filter(guilds_share__gt=0).aggregate(total=Sum('guilds_share'))[ -# 'total'] or 0 -# freezing_guilds_province_kill_request_total_wage += \ -# freezing_kill_house_requests.filter(province_kill_request__guilds_share__gt=0).aggregate(total=Sum( -# F('accepted_real_weight') * F('province_kill_request__wage') * ( -# F('province_kill_request__guilds_share_percent') / 100)))[ -# 'total'] or 0 -# guilds_chain_allocation_total_weight = \ -# chain_allocations.filter(guilds_share__gt=0).aggregate(total=Sum('weight'))[ -# 'total'] or 0 -# guilds_chain_allocation_total_wage = \ -# chain_allocations.filter(guilds_share__gt=0).aggregate(total=Sum('guilds_share'))[ -# 'total'] or 0 -# guilds_kill_house_free_live_bar_total_weight = \ -# free_bars.filter(buy_type='live', guilds_share__gt=0).aggregate(total=Sum('live_weight'))[ -# 'total'] or 0 -# guilds_kill_house_free_live_bar_total_wage = \ -# free_bars.filter(buy_type='live', guilds_share__gt=0).aggregate(total=Sum('guilds_share'))[ -# 'total'] or 0 +# }) # -# guilds_kill_house_free_carcases_bar_total_weight = \ -# free_bars.filter(buy_type='carcass', guilds_share__gt=0).aggregate( -# total=Sum('weight_of_carcasses'))[ -# 'total'] or 0 -# guilds_kill_house_free_carcases_bar_total_wage = \ -# free_bars.filter(buy_type='carcass', guilds_share__gt=0).aggregate(total=Sum('guilds_share'))[ -# 'total'] or 0 -# guilds_total_paid_wage += \ -# total_slaughter_transactions.filter(guilds_share__gt=0).aggregate(total=Sum('guilds_share'))[ -# 'total'] or 0 -# guilds_total_paid_wage += \ -# total_chain_company_transactions.filter(guilds_share__gt=0).aggregate(total=Sum('guilds_share'))[ -# 'total'] or 0 -# guilds_total_weight = guilds_province_kill_request_total_weight + freezing_guilds_province_kill_request_total_weight + guilds_chain_allocation_total_weight + guilds_kill_house_free_live_bar_total_weight + guilds_kill_house_free_carcases_bar_total_weight + guilds_poultry_request_out_total_weight -# guilds_total_wage = guilds_province_kill_request_total_wage + freezing_guilds_province_kill_request_total_wage + guilds_chain_allocation_total_wage + guilds_kill_house_free_live_bar_total_wage + guilds_kill_house_free_carcases_bar_total_wage -# guilds_total_unpaid_wage = guilds_total_wage - (guilds_total_paid_wage + guilds_poultry_request_out_total_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 = total_return_pure_province_carcasses_price * guilds_province_kill_request_percent +# 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_out_province_poultry_request_wage +# guilds_total_paid_wage = slaughter_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 +# guilds_total_paid_wage += poultry_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 +# guilds_total_unpaid_wage = guilds_total_wage - guilds_total_paid_wage # -# if role == 'SuperAdmin': -# return { -# "total_weight": total_weight, -# "total_wage": total_wage, -# "total_paid_wage": total_paid_wage, -# "total_unpaid_wage": total_wage - total_paid_wage, -# "province_kill_requests_total_wage": province_kill_requests_total_wage, -# "province_kill_requests_total_weight": province_kill_requests_total_weight, -# "freezing_province_kill_requests_total_wage": freezing_province_kill_requests_total_wage, -# "freezing_province_kill_requests_total_weight": freezing_province_kill_requests_total_weight, -# "chain_allocations_total_wage": chain_allocations_total_wage, -# "chain_allocations_total_weight": chain_allocations_total_weight, -# "free_bars_live_total_wage": free_bars_live_total_wage, -# "free_bars_live_total_weight": free_bars_live_total_weight, -# "free_bars_carcases_total_wage": free_bars_carcases_total_wage, -# "free_bars_carcases_total_weight": free_bars_carcases_total_weight, -# "poultry_request_out_total_wage" :poultry_request_out_total_wage, -# "poultry_request_out_total_weight" :poultry_request_out_total_weight, -# "shares": { -# "union_total_weight": union_total_weight, -# "union_total_wage": union_total_wage, -# "union_total_paid_wage": union_total_paid_wage, -# "union_total_unpaid_wage": union_total_unpaid_wage, -# "union_province_kill_request_total_wage": union_province_kill_request_total_wage, -# "union_kill_house_free_live_bar_total_wage": union_kill_house_free_live_bar_total_wage, -# "union_kill_house_free_carcases_bar_total_wage": union_kill_house_free_carcases_bar_total_wage, -# "union_chain_allocation_total_wage": union_chain_allocation_total_wage, -# "union_province_kill_request_total_weight": union_province_kill_request_total_weight, -# "union_kill_house_free_live_bar_total_weight": union_kill_house_free_live_bar_total_weight, -# "union_kill_house_free_carcases_bar_total_weight": union_kill_house_free_carcases_bar_total_weight, -# "union_chain_allocation_total_weight": union_chain_allocation_total_weight, -# "freezing_union_province_kill_request_total_wage": freezing_union_province_kill_request_total_wage, -# "freezing_union_province_kill_request_total_weight": freezing_union_province_kill_request_total_weight, -# "union_poultry_request_out_total_wage":union_poultry_request_out_total_wage, -# "union_poultry_request_out_total_weight":union_poultry_request_out_total_weight, +# shares_list.append({ +# "name": "صنف پروتئین", +# "out_province_poultry_request_wage": guilds_out_province_poultry_request_wage, +# "province_kill_request_wage": guilds_province_kill_request_wage, +# "return_province_kill_request_wage": 0, +# "free_buying_live_wage": guilds_free_buying_live_wage, +# "free_buying_carcasses_wage": guilds_free_buying_carcasses_wage, +# "free_sell_carcasses_wage": guilds_free_sell_carcasses_wage, +# "total_wage": guilds_total_wage, +# "total_paid_wage": guilds_total_paid_wage, +# "total_unpaid_wage": guilds_total_unpaid_wage, # -# "company_total_weight": company_total_weight, -# "company_total_wage": company_total_wage, -# "company_total_paid_wage": company_total_paid_wage, -# "company_total_unpaid_wage": company_total_unpaid_wage, -# "company_province_kill_request_total_wage": company_province_kill_request_total_wage, -# "company_kill_house_free_live_bar_total_wage": company_kill_house_free_live_bar_total_wage, -# "company_kill_house_free_carcases_bar_total_wage": company_kill_house_free_carcases_bar_total_wage, -# "company_chain_allocation_total_wage": company_chain_allocation_total_wage, -# "company_province_kill_request_total_weight": company_province_kill_request_total_weight, -# "company_kill_house_free_live_bar_total_weight": company_kill_house_free_live_bar_total_weight, -# "company_kill_house_free_carcases_bar_total_weight": company_kill_house_free_carcases_bar_total_weight, -# "company_chain_allocation_total_weight": company_chain_allocation_total_weight, -# "freezing_company_province_kill_request_total_wage": freezing_company_province_kill_request_total_wage, -# "freezing_company_province_kill_request_total_weight": freezing_company_province_kill_request_total_weight, -# "company_poultry_request_out_total_wage":company_poultry_request_out_total_wage, -# "company_poultry_request_out_total_weight":company_poultry_request_out_total_weight, +# }) # -# "guilds_total_weight": guilds_total_weight, -# "guilds_total_wage": guilds_total_wage, -# "guilds_total_paid_wage": guilds_total_paid_wage, -# "guilds_total_unpaid_wage": guilds_total_unpaid_wage, -# "guilds_province_kill_request_total_wage": guilds_province_kill_request_total_wage, -# "guilds_kill_house_free_live_bar_total_wage": guilds_kill_house_free_live_bar_total_wage, -# "guilds_kill_house_free_carcases_bar_total_wage": guilds_kill_house_free_carcases_bar_total_wage, -# "guilds_chain_allocation_total_wage": guilds_chain_allocation_total_wage, -# "guilds_province_kill_request_total_weight": guilds_province_kill_request_total_weight, -# "guilds_kill_house_free_live_bar_total_weight": guilds_kill_house_free_live_bar_total_weight, -# "guilds_kill_house_free_carcases_bar_total_weight": guilds_kill_house_free_carcases_bar_total_weight, -# "guilds_chain_allocation_total_weight": guilds_chain_allocation_total_weight, -# "freezing_guilds_province_kill_request_total_wage": freezing_guilds_province_kill_request_total_wage, -# "freezing_guilds_province_kill_request_total_weight": freezing_guilds_province_kill_request_total_weight, -# "guilds_poultry_request_out_total_wage" :guilds_poultry_request_out_total_wage, -# "guilds_poultry_request_out_total_weight" :guilds_poultry_request_out_total_weight, -# } -# } +# 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 = total_return_pure_province_carcasses_price * other_province_kill_request_percent +# 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_out_province_poultry_request_wage +# other_total_paid_wage = slaughter_transactions.aggregate(total=Sum('other_share'))['total'] or 0 +# other_total_paid_wage += poultry_transactions.aggregate(total=Sum('other_share'))['total'] or 0 +# other_total_unpaid_wage = other_total_wage - other_total_paid_wage +# +# shares_list.append({ +# "name": "دامپزشک", +# "out_province_poultry_request_wage": other_out_province_poultry_request_wage, +# "province_kill_request_wage": other_province_kill_request_wage, +# "return_province_kill_request_wage": 0, +# "free_buying_live_wage": other_free_buying_live_wage, +# "free_buying_carcasses_wage": other_free_buying_carcasses_wage, +# "free_sell_carcasses_wage": other_free_sell_carcasses_wage, +# "total_wage": other_total_wage, +# "total_paid_wage": other_total_paid_wage, +# "total_unpaid_wage": other_total_unpaid_wage, +# +# }) # # return { -# "total_weight": total_weight, -# "total_wage": total_wage, +# "wage_counting_type": wage_counting_type, +# "total_wage": total_price, # "total_paid_wage": total_paid_wage, -# "total_unpaid_wage": total_wage - total_paid_wage, -# "province_kill_requests_total_wage": province_kill_requests_total_wage, -# "province_kill_requests_total_weight": province_kill_requests_total_weight, -# "freezing_province_kill_requests_total_wage": freezing_province_kill_requests_total_wage, -# "freezing_province_kill_requests_total_weight": freezing_province_kill_requests_total_weight, -# "chain_allocations_total_wage": chain_allocations_total_wage, -# "chain_allocations_total_weight": chain_allocations_total_weight, -# "free_bars_live_total_wage": free_bars_live_total_wage, -# "free_bars_live_total_weight": free_bars_live_total_weight, -# "free_bars_carcases_total_wage": free_bars_carcases_total_wage, -# "free_bars_carcases_total_weight": free_bars_carcases_total_weight, -# "poultry_request_out_total_wage": poultry_request_out_total_wage, -# "poultry_request_out_total_weight": poultry_request_out_total_weight, +# "off": off, +# "total_unpaid_wage": total_price - (total_paid_wage + off), +# "out_province_poultry_request_weight": out_province_poultry_request_weight, +# "out_province_poultry_request_wage": out_province_poultry_request_wage, +# "province_kill_requests_total_wage": total_pure_province_carcasses_price, +# "province_kill_requests_total_weight": total_pure_province_carcasses_weight, +# "free_bars_live_total_wage": total_out_live_buying_province_carcasses_price, +# "free_bars_live_total_weight": real_total_out_live_buying_province_carcasses_weight, +# "free_bars_carcases_total_wage": total_out_carcasses_buying_province_carcasses_price, +# "free_bars_carcases_total_weight": total_out_carcasses_buying_province_carcasses_weight, +# "free_bars_out_province_carcases_total_wage": total_out_selling_province_carcasses_price, +# "free_bars_out_province_carcases_total_weight": total_out_selling_province_carcasses_weight, +# "total_province_live_weight": total_province_live_weight, +# "total_province_carcasses_weight": total_province_carcasses_weight, +# "province_live_wage_amount": province_live_wage_amount, +# "free_buying_live_weight_amount": free_buying_live_weight_amount, +# "free_buying_carcesses_weight_amount": free_buying_carcesses_weight_amount, +# "free_sell_carcesses_weight_amount": free_sell_carcesses_weight_amount, +# "out_province_poultry_request_wage_amount": out_province_poultry_request_wage_amount, +# "extra_company_amount": extra_company_amount, +# "shares": shares_list, +# "return_total_province_live_weight": return_total_province_live_weight, +# "total_return_pure_province_carcasses_price": total_return_pure_province_carcasses_price, # } - class TotalWageInformationSerializer(serializers.ModelSerializer): wage_info = serializers.SerializerMethodField('get_wage_info') @@ -4103,54 +3829,69 @@ class TotalWageInformationSerializer(serializers.ModelSerializer): else: - kill_houses = KillHouse.objects.filter(out_province=False, trash=False).order_by('id') + + total_wage=0 + total_paid_wage=0 + off=0 + out_province_poultry_request_weight=0 + out_province_poultry_request_wage=0 + total_pure_province_carcasses_price=0 + province_kill_requests_total_weight=0 + total_out_live_buying_province_carcasses_price=0 + free_bars_live_total_weight=0 + total_out_carcasses_buying_province_carcasses_price=0 + free_bars_carcases_total_weight=0 + total_out_selling_province_carcasses_price=0 + free_bars_out_province_carcases_total_weight=0 + total_province_live_weight=0 + total_province_carcasses_weight=0 + extra_company_amount=0 + shares_list=[] + return_total_province_live_weight=0 + total_return_pure_province_carcasses_price=0 + + + + + + total_union_province_kill_request_wage=0 + total_union_return_province_kill_request_wage=0 + total_union_free_buying_live_wage=0 + total_union_free_buying_carcasses_wage=0 + total_union_free_sell_carcasses_wage=0 + total_union_total_wage=0 + total_union_total_paid_wage=0 + total_union_total_unpaid_wage=0 + + total_company_province_kill_request_wage=0 + total_company_return_province_kill_request_wage=0 + total_company_free_buying_live_wage=0 + total_company_free_buying_carcasses_wage=0 + total_company_free_sell_carcasses_wage=0 + total_company_total_wage=0 + total_company_total_paid_wage=0 + total_company_total_unpaid_wage=0 + + + total_guilds_province_kill_request_wage=0 + total_guilds_return_province_kill_request_wage=0 + total_guilds_free_buying_live_wage=0 + total_guilds_free_buying_carcasses_wage=0 + total_guilds_free_sell_carcasses_wage=0 + total_guilds_total_wage=0 + total_guilds_total_paid_wage=0 + total_guilds_total_unpaid_wage=0 + + total_other_province_kill_request_wage=0 + total_other_return_province_kill_request_wage=0 + total_other_free_buying_live_wage=0 + total_other_free_buying_carcasses_wage=0 + total_other_free_sell_carcasses_wage=0 + total_other_total_wage=0 + total_other_total_paid_wage=0 + total_other_total_unpaid_wage=0 + if date1: - - province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, trash=False, - archive_wage=False, - return_to_province=False, - state__in=('pending', 'accepted'), - kill_request__recive_date__date__gte=date1, - kill_request__recive_date__date__lte=date2, - first_car_allocated_quantity=0).order_by( - 'id') - return_province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, - trash=True, return_trash=True, - archive_wage=False, - return_to_province=False, - state__in=('pending', 'accepted'), - kill_request__recive_date__date__gte=date1, - kill_request__recive_date__date__lte=date2, - first_car_allocated_quantity=0).order_by( - 'id') - kill_house_requests = KillHouseRequest.objects.filter( - Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( - Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( - Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, - kill_request__recive_date__date__gte=date1, kill_request__recive_date__date__lte=date2, - trash=False, calculate_status=True - ) - return_kill_house_requests = KillHouseRequest.objects.filter( - Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( - Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( - Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, - kill_request__recive_date__date__gte=date1, kill_request__recive_date__date__lte=date2, - trash=True, return_trash=True, calculate_status=True - ) - kill_house_free_bar_info = KillHouseFreeBarInformation.objects.filter(kill_house__in=kill_houses, - archive_wage=False, - calculate_status=True, - create_date__date__gte=date1, - create_date__date__lte=date2, - trash=False) - kill_house_free_sale_bar_info = KillHouseFreeSaleBarInformation.objects.filter( - kill_house__in=kill_houses, - archive_wage=False, calculate_status=True, date__date__gte=date1, date__date__lte=date2, - trash=False) - - slaughter_transactions = InternalTransaction.objects.filter( - kill_house__in=kill_houses, status='completed', date__date__gte=date1, date__date__lte=date2, - trash=False) poultry_transactions = InternalTransaction.objects.filter( poultry__isnull=False, status='completed', date__date__gte=date1, date__date__lte=date2, trash=False) @@ -4162,48 +3903,8 @@ class TotalWageInformationSerializer(serializers.ModelSerializer): send_date__date__lte=date2, wage_pay=True, has_wage=True, temporary_deleted=False) - difference_requests = BarDifferenceRequest.objects.filter(kill_house__in=kill_houses, trash=False, - create_date__date__gte=date1, - create_date__date__lte=date2, - state='accepted') - else: - province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, trash=False, - archive_wage=False, - return_to_province=False, - state__in=('pending', 'accepted'), - first_car_allocated_quantity=0).order_by( - 'id') - return_province_kill_requests = ProvinceKillRequest.objects.filter(killhouse_user__in=kill_houses, - trash=True, return_trash=True, - archive_wage=False, - return_to_province=False, - state__in=('pending', 'accepted'), - first_car_allocated_quantity=0).order_by( - 'id') - kill_house_requests = KillHouseRequest.objects.filter( - Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( - Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( - Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, - trash=False, calculate_status=True - ) - return_kill_house_requests = KillHouseRequest.objects.filter( - Q(Q(killhouse_user__in=kill_houses) & Q(killer__in=kill_houses)) | Q( - Q(killhouse_user__in=kill_houses) & Q(killer__isnull=True)) | Q( - Q(killhouse_user__in=kill_houses) | Q(killer__in=kill_houses)), archive_wage=False, - trash=True, return_trash=True, calculate_status=True - ) - kill_house_free_bar_info = KillHouseFreeBarInformation.objects.filter(kill_house__in=kill_houses, - archive_wage=False, - calculate_status=True, - trash=False) - kill_house_free_sale_bar_info = KillHouseFreeSaleBarInformation.objects.filter( - kill_house__in=kill_houses, - archive_wage=False, calculate_status=True, - trash=False) - slaughter_transactions = InternalTransaction.objects.filter( - kill_house__in=kill_houses, status='completed', - trash=False) + else: poultry_transactions = InternalTransaction.objects.filter( poultry__isnull=False, status='completed', trash=False) @@ -4214,8 +3915,7 @@ class TotalWageInformationSerializer(serializers.ModelSerializer): temporary_trash=False, wage_pay=True, has_wage=True, temporary_deleted=False) - difference_requests = BarDifferenceRequest.objects.filter(kill_house__in=kill_houses, trash=False, - state='accepted') + out_province_poultry_request_weight = \ poultry_requests.aggregate(total=Sum(F('quantity') * F('Index_weight')))[ @@ -4230,324 +3930,169 @@ class TotalWageInformationSerializer(serializers.ModelSerializer): 'total'] or 0 other_out_province_poultry_request_wage = poultry_requests.aggregate(total=Sum('other_share'))[ 'total'] or 0 - - off = kill_houses.aggregate(total=Sum('off'))[ - 'total'] or 0 - - total_paid_wage = slaughter_transactions.aggregate(total=Sum('amount'))[ - 'total'] or 0 - total_paid_wage += poultry_transactions.aggregate(total=Sum('amount'))[ + total_paid_wage = poultry_transactions.aggregate(total=Sum('amount'))[ 'total'] or 0 + total_union_total_paid_wage += poultry_transactions.aggregate(total=Sum('union_share'))['total'] or 0 + total_company_total_paid_wage += poultry_transactions.aggregate(total=Sum('company_share'))['total'] or 0 + total_guilds_total_paid_wage += poultry_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 + total_other_total_paid_wage += poultry_transactions.aggregate(total=Sum('other_share'))['total'] or 0 - total_province_live_weight = province_kill_requests.aggregate(total=Sum('total_killed_weight'))[ - 'total'] or 0 - total_province_live_weight += kill_house_requests.aggregate(total=Sum('accepted_real_weight'))['total'] or 0 - # total_out_selling_province_carcasses_weight = \ - # kill_house_free_sale_bar_info.aggregate(total=Sum('real_weight_of_carcasses'))['total'] or 0 - # total_out_selling_province_quarantine_carcasses_weight = \ - # kill_house_free_sale_bar_info.aggregate(total=Sum('quarantine_weight_of_carcasses'))['total'] or 0 - # sum_quarantine_carcasses_weight = \ - # kill_house_free_sale_bar_info.filter(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() - # ) - # ) - # ) - # total_out_selling_province_quarantine_carcasses_weight = sum_quarantine_carcasses_weight[ - # 'total_weight'] or 0 - total_province_live_weight += \ - difference_requests.aggregate(total=Sum('weight'))['total'] or 0 - difference_requests_weight = \ - difference_requests.aggregate(total=Sum('weight'))['total'] or 0 - return_total_province_live_weight = \ - return_province_kill_requests.aggregate(total=Sum('total_killed_weight'))[ - 'total'] or 0 - return_total_province_live_weight += \ - return_kill_house_requests.aggregate(total=Sum('accepted_real_weight'))['total'] or 0 - 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_wage +=out_province_poultry_request_wage + # kill_houses = KillHouse.objects.filter(out_province=False, trash=False).order_by('id') + kill_house_ids = KillHousePercentage.objects.filter(kill_house__type='exclusive', trash=False).values_list( + 'kill_house', flat=True) + kill_houses = KillHouse.objects.filter(out_province=False, trash=False).exclude( + id__in=kill_house_ids).order_by( + 'id') + for kill_house in kill_houses: + finance_info =get_total_wage_info(kill_house) - if wage_counting_type == 'live': - total_province_carcasses_weight = total_province_live_weight + total_wage += finance_info['total_wage'] + total_paid_wage += finance_info['total_paid_wage'] + off += finance_info['off'] + # out_province_poultry_request_weight += finance_info['total_wage'] + # out_province_poultry_request_wage += finance_info['total_wage'] + total_pure_province_carcasses_price += finance_info['province_kill_requests_total_wage'] + province_kill_requests_total_weight += finance_info['province_kill_requests_total_weight'] + total_out_live_buying_province_carcasses_price += finance_info['free_bars_live_total_wage'] + free_bars_live_total_weight += finance_info['free_bars_live_total_weight'] + total_out_carcasses_buying_province_carcasses_price += finance_info['free_bars_carcases_total_wage'] + free_bars_carcases_total_weight += finance_info['free_bars_carcases_total_weight'] + total_out_selling_province_carcasses_price += finance_info['free_bars_out_province_carcases_total_wage'] + free_bars_out_province_carcases_total_weight += finance_info['free_bars_out_province_carcases_total_weight'] + total_province_live_weight += finance_info['total_province_live_weight'] + total_province_carcasses_weight += finance_info['total_province_carcasses_weight'] + 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'] + total_union_province_kill_request_wage += finance_info['union_province_kill_request_wage'] + total_union_return_province_kill_request_wage += finance_info['return_union_province_kill_request_wage'] + total_union_free_buying_live_wage += finance_info['union_free_buying_live_wage'] + total_union_free_buying_carcasses_wage += finance_info['union_free_buying_carcasses_wage'] + total_union_free_sell_carcasses_wage += finance_info['union_free_sell_carcasses_wage'] + total_union_total_wage += finance_info['union_total_wage'] + total_union_total_paid_wage += finance_info['union_total_paid_wage'] + total_union_total_unpaid_wage += finance_info['union_total_unpaid_wage'] - total_pure_province_carcasses_weight = total_province_carcasses_weight - else: - return_total_province_live_weight = int(return_total_province_live_weight * 0.75) - total_province_carcasses_weight = total_province_live_weight * 0.75 - difference_requests_weight = difference_requests_weight * 0.75 + total_company_province_kill_request_wage += finance_info['company_province_kill_request_wage'] + total_company_return_province_kill_request_wage += finance_info['return_company_province_kill_request_wage'] + total_company_free_buying_live_wage += finance_info['company_free_buying_live_wage'] + total_company_free_buying_carcasses_wage += finance_info['company_free_buying_carcasses_wage'] + total_company_free_sell_carcasses_wage += finance_info['company_free_sell_carcasses_wage'] + total_company_total_wage += finance_info['company_total_wage'] + total_company_total_paid_wage += finance_info['company_total_paid_wage'] + total_company_total_unpaid_wage += finance_info['company_total_unpaid_wage'] - total_out_carcasses_buying_for_pure_province_carcasses_weight = \ - kill_house_free_bar_info.aggregate(total=Sum('weight_of_carcasses'))['total'] or 0 - if date1: - total_pure_province_carcasses_weight = total_province_carcasses_weight - get_difference_carcasses_weight( - kill_houses, date1, date2) - else: - total_pure_province_carcasses_weight = total_province_carcasses_weight - get_difference_carcasses_weight( - kill_houses) - total_out_live_buying_province_carcasses_weight = \ - kill_house_free_bar_info.filter(buy_type='live').aggregate(total=Sum('live_weight'))['total'] or 0 - real_total_out_live_buying_province_carcasses_weight = total_out_live_buying_province_carcasses_weight - 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) + total_guilds_province_kill_request_wage += finance_info['guilds_province_kill_request_wage'] + total_guilds_return_province_kill_request_wage += finance_info['return_guilds_province_kill_request_wage'] + total_guilds_free_buying_live_wage += finance_info['guilds_free_buying_live_wage'] + total_guilds_free_buying_carcasses_wage += finance_info['guilds_free_buying_carcasses_wage'] + total_guilds_free_sell_carcasses_wage += finance_info['guilds_free_sell_carcasses_wage'] + total_guilds_total_wage += finance_info['guilds_total_wage'] + total_guilds_total_paid_wage += finance_info['guilds_total_paid_wage'] + total_guilds_total_unpaid_wage += finance_info['guilds_total_unpaid_wage'] - 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 + total_other_province_kill_request_wage += finance_info['other_province_kill_request_wage'] + total_other_return_province_kill_request_wage += finance_info['return_other_province_kill_request_wage'] + total_other_free_buying_live_wage += finance_info['other_free_buying_live_wage'] + total_other_free_buying_carcasses_wage += finance_info['other_free_buying_carcasses_wage'] + total_other_free_sell_carcasses_wage += finance_info['other_free_sell_carcasses_wage'] + total_other_total_wage += finance_info['other_total_wage'] + total_other_total_paid_wage += finance_info['other_total_paid_wage'] + total_other_total_unpaid_wage += finance_info['other_total_unpaid_wage'] - 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 + shares_list.append({ + "name": "اتحادیه", + "out_province_poultry_request_wage": union_out_province_poultry_request_wage, + "province_kill_request_wage": total_union_province_kill_request_wage, + "return_province_kill_request_wage": total_union_return_province_kill_request_wage, + "free_buying_live_wage": total_union_free_buying_live_wage, + "free_buying_carcasses_wage": total_union_free_buying_carcasses_wage, + "free_sell_carcasses_wage": total_union_free_sell_carcasses_wage, + "total_wage": total_union_total_wage, + "total_paid_wage": total_union_total_paid_wage, + "total_unpaid_wage": total_union_total_unpaid_wage, - 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 + shares_list.append({ + "name": "شرکت", + "out_province_poultry_request_wage": company_out_province_poultry_request_wage, + "province_kill_request_wage": total_company_province_kill_request_wage, + "return_province_kill_request_wage": total_company_return_province_kill_request_wage, + "free_buying_live_wage": total_company_free_buying_live_wage, + "free_buying_carcasses_wage": total_company_free_buying_carcasses_wage, + "free_sell_carcasses_wage": total_company_free_sell_carcasses_wage, + "total_wage": total_company_total_wage, + "total_paid_wage": total_company_total_paid_wage, + "total_unpaid_wage": total_company_total_unpaid_wage, - total_out_live_buying_province_carcasses_weight = before_total_out_live_buying_province_carcasses_weight + after_total_out_live_buying_province_carcasses_weight - company_before_total_out_live_buying_province_carcasses_weight = before_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 + shares_list.append({ + "name": "صنف پروتئین", + "out_province_poultry_request_wage": guilds_out_province_poultry_request_wage, + "province_kill_request_wage": total_guilds_province_kill_request_wage, + "return_province_kill_request_wage": 0, + "free_buying_live_wage": total_guilds_free_buying_live_wage, + "free_buying_carcasses_wage": total_guilds_free_buying_carcasses_wage, + "free_sell_carcasses_wage": total_guilds_free_sell_carcasses_wage, + "total_wage": total_guilds_total_wage, + "total_paid_wage": total_guilds_total_paid_wage, + "total_unpaid_wage": total_guilds_total_unpaid_wage, - 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 - total_pure_province_carcasses_price = total_pure_province_carcasses_weight * province_live_wage_amount - difference_requests_price = difference_requests_weight * province_live_wage_amount - total_return_pure_province_carcasses_price = return_total_province_live_weight * province_live_wage_amount - total_out_selling_province_carcasses_price = total_out_selling_province_carcasses_weight * free_sell_carcesses_weight_amount + }) - if new_out_selling_count_wage: - total_out_live_buying_province_carcasses_price = int( - (before_total_out_live_buying_province_carcasses_weight * before_out_buying_count_wage_amount) + ( - after_total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount)) - before_total_out_live_buying_province_carcasses_price = before_total_out_live_buying_province_carcasses_weight * before_out_buying_count_wage_amount - else: - total_out_live_buying_province_carcasses_price = total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount - # total_out_live_buying_province_carcasses_price = total_out_live_buying_province_carcasses_weight * free_buying_live_weight_amount - total_out_carcasses_buying_province_carcasses_price = total_out_carcasses_buying_province_carcasses_weight * free_buying_carcesses_weight_amount - total_price = total_pure_province_carcasses_price + total_out_selling_province_carcasses_price + total_out_live_buying_province_carcasses_price + total_out_carcasses_buying_province_carcasses_price + out_province_poultry_request_wage + extra_company_amount + total_return_pure_province_carcasses_price + shares_list.append({ + "name": "دامپزشک", + "out_province_poultry_request_wage": other_out_province_poultry_request_wage, + "province_kill_request_wage": total_other_province_kill_request_wage, + "return_province_kill_request_wage": 0, + "free_buying_live_wage": total_other_free_buying_live_wage, + "free_buying_carcasses_wage": total_other_free_buying_carcasses_wage, + "free_sell_carcasses_wage": total_other_free_sell_carcasses_wage, + "total_wage": total_other_total_wage, + "total_paid_wage": total_other_total_paid_wage, + "total_unpaid_wage": total_other_total_unpaid_wage, - 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 - union_province_kill_request_wage = total_pure_province_carcasses_price * union_province_kill_request_percent - return_union_province_kill_request_wage = total_return_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 + union_out_province_poultry_request_wage + return_union_province_kill_request_wage - union_total_paid_wage = slaughter_transactions.aggregate(total=Sum('union_share'))['total'] or 0 - union_total_paid_wage += poultry_transactions.aggregate(total=Sum('union_share'))['total'] or 0 - union_total_unpaid_wage = union_total_wage - union_total_paid_wage - shares_list.append({ - "name": "اتحادیه", - "out_province_poultry_request_wage": union_out_province_poultry_request_wage, - "province_kill_request_wage": union_province_kill_request_wage, - "return_province_kill_request_wage": return_union_province_kill_request_wage, - "free_buying_live_wage": union_free_buying_live_wage, - "free_buying_carcasses_wage": union_free_buying_carcasses_wage, - "free_sell_carcasses_wage": union_free_sell_carcasses_wage, - "total_wage": union_total_wage, - "total_paid_wage": union_total_paid_wage, - "total_unpaid_wage": union_total_unpaid_wage, - - }) - - 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 = total_return_pure_province_carcasses_price * guilds_province_kill_request_percent - other_return_province_kill_request_wage = total_return_pure_province_carcasses_price * other_province_kill_request_percent - - 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 = ( - total_return_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 + company_out_province_poultry_request_wage + return_company_province_kill_request_wage - company_total_paid_wage = slaughter_transactions.aggregate(total=Sum('company_share'))['total'] or 0 - company_total_paid_wage += poultry_transactions.aggregate(total=Sum('company_share'))['total'] or 0 - # company_total_pure_paid_wage = company_total_paid_wage - (company_total_paid_wage * 0.08)) - company_total_unpaid_wage = company_total_wage - company_total_paid_wage - - shares_list.append({ - "name": "شرکت", - "out_province_poultry_request_wage": company_out_province_poultry_request_wage, - "province_kill_request_wage": company_province_kill_request_wage, - "return_province_kill_request_wage": return_company_province_kill_request_wage, - "free_buying_live_wage": company_free_buying_live_wage, - "free_buying_carcasses_wage": company_free_buying_carcasses_wage, - "free_sell_carcasses_wage": company_free_sell_carcasses_wage, - "total_wage": company_total_wage, - "total_paid_wage": company_total_paid_wage, - "total_unpaid_wage": company_total_unpaid_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 = total_return_pure_province_carcasses_price * guilds_province_kill_request_percent - 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_out_province_poultry_request_wage - guilds_total_paid_wage = slaughter_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 - guilds_total_paid_wage += poultry_transactions.aggregate(total=Sum('guilds_share'))['total'] or 0 - guilds_total_unpaid_wage = guilds_total_wage - guilds_total_paid_wage - - shares_list.append({ - "name": "صنف پروتئین", - "out_province_poultry_request_wage": guilds_out_province_poultry_request_wage, - "province_kill_request_wage": guilds_province_kill_request_wage, - "return_province_kill_request_wage": 0, - "free_buying_live_wage": guilds_free_buying_live_wage, - "free_buying_carcasses_wage": guilds_free_buying_carcasses_wage, - "free_sell_carcasses_wage": guilds_free_sell_carcasses_wage, - "total_wage": guilds_total_wage, - "total_paid_wage": guilds_total_paid_wage, - "total_unpaid_wage": guilds_total_unpaid_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 = total_return_pure_province_carcasses_price * other_province_kill_request_percent - 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_out_province_poultry_request_wage - other_total_paid_wage = slaughter_transactions.aggregate(total=Sum('other_share'))['total'] or 0 - other_total_paid_wage += poultry_transactions.aggregate(total=Sum('other_share'))['total'] or 0 - other_total_unpaid_wage = other_total_wage - other_total_paid_wage - - shares_list.append({ - "name": "دامپزشک", - "out_province_poultry_request_wage": other_out_province_poultry_request_wage, - "province_kill_request_wage": other_province_kill_request_wage, - "return_province_kill_request_wage": 0, - "free_buying_live_wage": other_free_buying_live_wage, - "free_buying_carcasses_wage": other_free_buying_carcasses_wage, - "free_sell_carcasses_wage": other_free_sell_carcasses_wage, - "total_wage": other_total_wage, - "total_paid_wage": other_total_paid_wage, - "total_unpaid_wage": other_total_unpaid_wage, - - }) - - return { - "wage_counting_type": wage_counting_type, - "total_wage": total_price, - "total_paid_wage": total_paid_wage, - "off": off, - "total_unpaid_wage": total_price - (total_paid_wage + off), - "out_province_poultry_request_weight": out_province_poultry_request_weight, - "out_province_poultry_request_wage": out_province_poultry_request_wage, - "province_kill_requests_total_wage": total_pure_province_carcasses_price, - "province_kill_requests_total_weight": total_pure_province_carcasses_weight, - "free_bars_live_total_wage": total_out_live_buying_province_carcasses_price, - "free_bars_live_total_weight": real_total_out_live_buying_province_carcasses_weight, - "free_bars_carcases_total_wage": total_out_carcasses_buying_province_carcasses_price, - "free_bars_carcases_total_weight": total_out_carcasses_buying_province_carcasses_weight, - "free_bars_out_province_carcases_total_wage": total_out_selling_province_carcasses_price, - "free_bars_out_province_carcases_total_weight": total_out_selling_province_carcasses_weight, - "total_province_live_weight": total_province_live_weight, - "total_province_carcasses_weight": total_province_carcasses_weight, - "province_live_wage_amount": province_live_wage_amount, - "free_buying_live_weight_amount": free_buying_live_weight_amount, - "free_buying_carcesses_weight_amount": free_buying_carcesses_weight_amount, - "free_sell_carcesses_weight_amount": free_sell_carcesses_weight_amount, - "out_province_poultry_request_wage_amount": out_province_poultry_request_wage_amount, - "extra_company_amount": extra_company_amount, - "shares": shares_list, - "return_total_province_live_weight": return_total_province_live_weight, - "total_return_pure_province_carcasses_price": total_return_pure_province_carcasses_price, - } + return { + "wage_counting_type": wage_counting_type, + "total_wage": total_wage, + "total_paid_wage": total_paid_wage, + "off": off, + "total_unpaid_wage": total_wage - (total_paid_wage + off), + "out_province_poultry_request_weight": out_province_poultry_request_weight, + "out_province_poultry_request_wage": out_province_poultry_request_wage, + "province_kill_requests_total_wage": total_pure_province_carcasses_price, + "province_kill_requests_total_weight": province_kill_requests_total_weight, + "free_bars_live_total_wage": total_out_live_buying_province_carcasses_price, + "free_bars_live_total_weight": free_bars_live_total_weight, + "free_bars_carcases_total_wage": total_out_carcasses_buying_province_carcasses_price, + "free_bars_carcases_total_weight": free_bars_carcases_total_weight, + "free_bars_out_province_carcases_total_wage": total_out_selling_province_carcasses_price, + "free_bars_out_province_carcases_total_weight": free_bars_out_province_carcases_total_weight, + "total_province_live_weight": total_province_live_weight, + "total_province_carcasses_weight": total_province_carcasses_weight, + "province_live_wage_amount": province_live_wage_amount, + "free_buying_live_weight_amount": free_buying_live_weight_amount, + "free_buying_carcesses_weight_amount": free_buying_carcesses_weight_amount, + "free_sell_carcesses_weight_amount": free_sell_carcesses_weight_amount, + "out_province_poultry_request_wage_amount": out_province_poultry_request_wage_amount, + "extra_company_amount": extra_company_amount, + "shares": shares_list, + "return_total_province_live_weight": return_total_province_live_weight, + "total_return_pure_province_carcasses_price": total_return_pure_province_carcasses_price, + } class ParentCompanyTotalWageInformationSerializer(serializers.ModelSerializer):