From 073ef596dbf6ad20ce84bd0a3cde62873b263e07 Mon Sep 17 00:00:00 2001 From: wilsongomez Date: Tue, 10 May 2022 17:16:51 -0500 Subject: [PATCH] add option 60 40 payroll --- payroll.py | 25 +++++++++++++++++++++++++ view/wage_type_form.xml | 2 ++ wage_type.py | 1 + 3 files changed, 28 insertions(+) diff --git a/payroll.py b/payroll.py index 3fa0e9c..0e05299 100644 --- a/payroll.py +++ b/payroll.py @@ -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 diff --git a/view/wage_type_form.xml b/view/wage_type_form.xml index 74786dd..95f296e 100644 --- a/view/wage_type_form.xml +++ b/view/wage_type_form.xml @@ -19,5 +19,7 @@ this repository contains the full copyright notices and license terms. -->