From 3fc96fc2031dd88725d031bfe75ce5b30cf632ea Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Thu, 29 Sep 2022 16:55:34 +0000 Subject: [PATCH 1/3] [IMP] l10n_pe_hr_payroll: add logger for debugging 5th cat. --- l10n_pe_hr_payroll/models/rules/ir_5ta_cat.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/l10n_pe_hr_payroll/models/rules/ir_5ta_cat.py b/l10n_pe_hr_payroll/models/rules/ir_5ta_cat.py index a5acbd2e..167e1320 100644 --- a/l10n_pe_hr_payroll/models/rules/ir_5ta_cat.py +++ b/l10n_pe_hr_payroll/models/rules/ir_5ta_cat.py @@ -1,6 +1,11 @@ # Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details. from datetime import date +from pprint import pformat + +import logging +_logger = logging.getLogger(__name__) + def ir_5ta_cat(payslip, categories, worked_days, inputs): basic_wage = categories.BASIC @@ -33,6 +38,8 @@ def ir_5ta_cat(payslip, categories, worked_days, inputs): # IF employee's `first_contract_date` is in current year # THEN we can pro-rate the period (reduce withholding) + # TODO replace with just date_from on contract or something + # we are told that every year new contracts will be needed date_hired = payslip.dict.contract_id.first_contract_date payslip_date_end = payslip.dict.date_to hired_in_year = date_hired.year == payslip_date_end.year @@ -92,4 +99,5 @@ def ir_5ta_cat(payslip, categories, worked_days, inputs): return wage_period, (remaining_tax / wage_period * 100.0) tax = -(total_tax - ytd_tax) / pay_periods_at_current + _logger.info('ir_5ta_cat locals: ' + str(pformat(locals()))) return wage_period, (tax / wage_period * 100.0) From 9fbc5142be6c5e615731cf7d936d6a9654e64e2a Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Thu, 29 Sep 2022 17:47:56 +0000 Subject: [PATCH 2/3] [FIX] hr_payroll_hibou: sum wage on paid slips --- hr_payroll_hibou/models/browsable_object.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hr_payroll_hibou/models/browsable_object.py b/hr_payroll_hibou/models/browsable_object.py index d93e0eee..a632377b 100644 --- a/hr_payroll_hibou/models/browsable_object.py +++ b/hr_payroll_hibou/models/browsable_object.py @@ -35,7 +35,7 @@ class InputLine(BrowsableObject): self.__browsable_query = """ SELECT sum(amount) as sum FROM hr_payslip as hp, hr_payslip_input as pi - WHERE hp.employee_id = %s AND hp.state = 'done' + WHERE hp.employee_id = %s AND hp.state in ('done', 'paid') AND hp.{sum_field} >= %s AND hp.date_to <= %s AND hp.id = pi.payslip_id AND pi.code = %s""".format(sum_field=sum_field) def sum(self, code, from_date, to_date=None): @@ -51,7 +51,7 @@ class WorkedDays(BrowsableObject): self.__browsable_query = """ SELECT sum(number_of_days) as number_of_days, sum(number_of_hours) as number_of_hours FROM hr_payslip as hp, hr_payslip_worked_days as pi - WHERE hp.employee_id = %s AND hp.state = 'done' + WHERE hp.employee_id = %s AND hp.state in ('done', 'paid') AND hp.{sum_field} >= %s AND hp.date_to <= %s AND hp.id = pi.payslip_id AND pi.code = %s""".format(sum_field=sum_field) def _sum(self, code, from_date, to_date=None): @@ -77,7 +77,7 @@ class Payslips(BrowsableObject): self.__browsable_query_rule = """ SELECT sum(case when hp.credit_note is not True then (pl.total) else (-pl.total) end) FROM hr_payslip as hp, hr_payslip_line as pl - WHERE hp.employee_id = %s AND hp.state = 'done' + WHERE hp.employee_id = %s AND hp.state in ('done', 'paid') AND hp.{sum_field} >= %s AND hp.date_to <= %s AND hp.id = pl.slip_id AND pl.code = %s""".format(sum_field=sum_field) # Original (non-recursive) # self.__browsable_query_category = """ @@ -105,7 +105,7 @@ class Payslips(BrowsableObject): SELECT sum(case when hp.credit_note is not True then (pl.total) else (-pl.total) end) FROM hr_payslip as hp, hr_payslip_line as pl - WHERE hp.employee_id = %s AND hp.state = 'done' + WHERE hp.employee_id = %s AND hp.state in ('done', 'paid') AND hp.{sum_field} >= %s AND hp.date_to <= %s AND hp.id = pl.slip_id AND pl.category_id in (SELECT id from category_ids)""".format(sum_field=sum_field) From 7d0a537bde575d7827f3e320b665ae055c21eb24 Mon Sep 17 00:00:00 2001 From: Jared Kipe Date: Thu, 29 Sep 2022 20:22:54 +0000 Subject: [PATCH 3/3] [IMP] l10n_pe_hr_payroll: support household allowance, and EE EPS rule --- l10n_pe_hr_payroll/data/base.xml | 36 +++++++++++++++++++ l10n_pe_hr_payroll/data/ir_5ta_cat_rules.xml | 13 +++++++ .../models/pe_payroll_config.py | 4 +++ l10n_pe_hr_payroll/models/rules/ir_5ta_cat.py | 3 +- .../views/pe_payroll_config_views.xml | 2 ++ 5 files changed, 57 insertions(+), 1 deletion(-) diff --git a/l10n_pe_hr_payroll/data/base.xml b/l10n_pe_hr_payroll/data/base.xml index bb664c89..ae59e259 100644 --- a/l10n_pe_hr_payroll/data/base.xml +++ b/l10n_pe_hr_payroll/data/base.xml @@ -153,4 +153,40 @@ + + + + Peru Minimum Wage + pe_min_wage + + + + 930.0 + + + + + + Peru Minor Dependent Rate + pe_minor_dependent_rate + + + + 10.0 + + + + + + python + result = contract.pe_payroll_config_value('has_minor_dependent') + code + result, result_rate = payslip.rule_parameter('pe_min_wage'), payslip.rule_parameter('pe_minor_dependent_rate') + BASIC_HOUSEHOLD + + Basic: Household Allowance + + + + diff --git a/l10n_pe_hr_payroll/data/ir_5ta_cat_rules.xml b/l10n_pe_hr_payroll/data/ir_5ta_cat_rules.xml index 123dbb5f..b9ca44cf 100644 --- a/l10n_pe_hr_payroll/data/ir_5ta_cat_rules.xml +++ b/l10n_pe_hr_payroll/data/ir_5ta_cat_rules.xml @@ -80,6 +80,19 @@ + + + + + Household Allowance + ALW_GRATIF_HOUSEHOLD + python + result = contract.pe_payroll_config_value('has_minor_dependent') + code + result, result_rate = payslip.rule_parameter('pe_min_wage'), payslip.rule_parameter('pe_minor_dependent_rate') + + + diff --git a/l10n_pe_hr_payroll/models/pe_payroll_config.py b/l10n_pe_hr_payroll/models/pe_payroll_config.py index 97d58319..5a8e4e13 100644 --- a/l10n_pe_hr_payroll/models/pe_payroll_config.py +++ b/l10n_pe_hr_payroll/models/pe_payroll_config.py @@ -10,6 +10,7 @@ class HRContractPEPayrollConfig(models.Model): name = fields.Char(string="Description") employee_id = fields.Many2one('hr.employee', string="Employee", required=True) + has_minor_dependent = fields.Boolean(string='Has Minor Dependent', help='Eligible for Household Allowance') ee_5ta_cat_exempt = fields.Boolean(string='Exempt from 5th Cat. withholding.') retirement_type = fields.Selection([ @@ -34,6 +35,9 @@ class HRContractPEPayrollConfig(models.Model): ('essalud', 'Essalud'), ('eps', 'EPS'), ], string='Company Social Services', default='essalud') + comp_ss_eps_ee_rule_id = fields.Many2one('hr.salary.rule', string='Employee Social Security EPS Rule', + domain=[('code', '=like', 'EE_PE_EPS%')], + help="Rule code prefix 'EE_PE_EPS' to select here.") comp_ss_eps_rule_id = fields.Many2one('hr.salary.rule', string='Company Social Security EPS Rule', domain=[('code', '=like', 'ER_PE_EPS%')], help="Rule code prefix 'ER_PE_EPS' to select here.") diff --git a/l10n_pe_hr_payroll/models/rules/ir_5ta_cat.py b/l10n_pe_hr_payroll/models/rules/ir_5ta_cat.py index 167e1320..6945274a 100644 --- a/l10n_pe_hr_payroll/models/rules/ir_5ta_cat.py +++ b/l10n_pe_hr_payroll/models/rules/ir_5ta_cat.py @@ -99,5 +99,6 @@ def ir_5ta_cat(payslip, categories, worked_days, inputs): return wage_period, (remaining_tax / wage_period * 100.0) tax = -(total_tax - ytd_tax) / pay_periods_at_current - _logger.info('ir_5ta_cat locals: ' + str(pformat(locals()))) + # uncomment to see a lot of detail + # _logger.info('ir_5ta_cat locals: ' + str(pformat(locals()))) return wage_period, (tax / wage_period * 100.0) diff --git a/l10n_pe_hr_payroll/views/pe_payroll_config_views.xml b/l10n_pe_hr_payroll/views/pe_payroll_config_views.xml index 3cb941f4..6be79864 100644 --- a/l10n_pe_hr_payroll/views/pe_payroll_config_views.xml +++ b/l10n_pe_hr_payroll/views/pe_payroll_config_views.xml @@ -26,6 +26,7 @@ + @@ -34,6 +35,7 @@

Not supported. Specify rule.

+