add option 60 40 payroll

This commit is contained in:
wilsongomez 2022-05-10 17:16:51 -05:00
parent aaa4f48fdc
commit 073ef596db
3 changed files with 28 additions and 0 deletions

View File

@ -492,6 +492,7 @@ class Payroll(metaclass=PoolMeta):
super(Payroll, self).set_preliquidation(extras, discounts)
self.save()
self.update_wage_no_salary()
self.recompute_lines()
def set_events(self):
pool = Pool()
@ -698,6 +699,30 @@ class Payroll(metaclass=PoolMeta):
return sum([l.amount for l in lines if not l.reconciled])
def recompute_lines(self):
PayrollLine = Pool().get('staff.payroll.line')
amounts_60_40 = []
wages_60_40 = []
for line in self.lines:
wage = line.wage_type
if wage.definition == 'payment':
if wage.salary_constitute:
amounts_60_40.append(line.amount)
elif wage.wage_type_60_40:
wages_60_40.append(line)
amounts_60_40.append(line.amount)
amount_wages_60_40 = sum([l.amount for l in wages_60_40])
amount_to_validate = sum(amounts_60_40) * Decimal(0.4) < amount_wages_60_40
if amounts_60_40 and wages_60_40 and amount_to_validate:
amount_dif = amount_wages_60_40 - sum(amounts_60_40) * Decimal(0.4)
lines_to_create = []
for l in wages_60_40:
new_unit_value = Decimal(str(round((amount_dif * (l.amount/amount_wages_60_40)),2)))
unit_value = Decimal(str(round((l.amount - new_unit_value), 2)))
lines_to_create.append(self.get_line(l.wage_type.wage_type_60_40, 1, new_unit_value))
PayrollLine.write([l], {
'unit_value': unit_value,
})
PayrollLine.create(lines_to_create)
super(Payroll, self).recompute_lines()
self.update_wage_no_salary()
line_tax = None

View File

@ -19,5 +19,7 @@ this repository contains the full copyright notices and license terms. -->
<field name="round_amounts"/>
<label name="provision_cancellation"/>
<field name="provision_cancellation"/>
<label name="wage_type_60_40"/>
<field name="wage_type_60_40"/>
</xpath>
</data>

View File

@ -25,6 +25,7 @@ class WageType(metaclass=PoolMeta):
round_amounts = fields.Selection(ROUND_AMOUNTS, 'Rounds amounts',
help='Approximates the highest value in hundreds')
provision_cancellation = fields.Many2One('staff.wage_type', 'Cancellation of Provision')
wage_type_60_40 = fields.Many2One('staff.wage_type', 'Wage Type 60/40', help='select wage type for set 60/40')
@classmethod
def __setup__(cls):