mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[FIX] l10n_pe_hr_payroll: default structure
This commit is contained in:
@@ -16,6 +16,10 @@
|
|||||||
]"/>
|
]"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record id="l10n_pe_hr_payroll.structure_type_employee" model="hr.payroll.structure.type">
|
||||||
|
<field name="default_struct_id" ref="hr_payroll_structure"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
<record id="structure_type_employee_4ta_cat" model="hr.payroll.structure.type">
|
<record id="structure_type_employee_4ta_cat" model="hr.payroll.structure.type">
|
||||||
<field name="name">Peru Employee (4ta Cat.)</field>
|
<field name="name">Peru Employee (4ta Cat.)</field>
|
||||||
<field name="default_resource_calendar_id" ref="resource.resource_calendar_std"/>
|
<field name="default_resource_calendar_id" ref="resource.resource_calendar_std"/>
|
||||||
@@ -28,6 +32,10 @@
|
|||||||
<field name="type_id" ref="l10n_pe_hr_payroll.structure_type_employee_4ta_cat"/>
|
<field name="type_id" ref="l10n_pe_hr_payroll.structure_type_employee_4ta_cat"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<record id="l10n_pe_hr_payroll.structure_type_employee_4ta_cat" model="hr.payroll.structure.type">
|
||||||
|
<field name="default_struct_id" ref="hr_payroll_structure_4ta_cat"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
<!-- AFP -->
|
<!-- AFP -->
|
||||||
<record id="hr_payroll_category_ee_pe_afp" model="hr.salary.rule.category">
|
<record id="hr_payroll_category_ee_pe_afp" model="hr.salary.rule.category">
|
||||||
<field name="name">EE: AFP</field>
|
<field name="name">EE: AFP</field>
|
||||||
|
|||||||
@@ -1,65 +1,33 @@
|
|||||||
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
# Part of Hibou Suite Professional. See LICENSE_PROFESSIONAL file for full copyright and licensing details.
|
||||||
|
|
||||||
from logging import getLogger
|
from odoo.addons.hr_payroll_hibou.tests import common
|
||||||
from sys import float_info as sys_float_info
|
|
||||||
from collections import defaultdict
|
|
||||||
from datetime import timedelta
|
|
||||||
|
|
||||||
from odoo.tests import common
|
|
||||||
from odoo.tools.float_utils import float_round as odoo_float_round
|
|
||||||
|
|
||||||
|
|
||||||
def process_payslip(payslip):
|
process_payslip = common.process_payslip
|
||||||
try:
|
|
||||||
payslip.action_payslip_done()
|
|
||||||
except AttributeError:
|
|
||||||
# v9
|
|
||||||
payslip.process_sheet()
|
|
||||||
|
|
||||||
|
|
||||||
class TestPePayslip(common.TransactionCase):
|
class TestPePayslip(common.TestPayslip):
|
||||||
debug = False
|
|
||||||
_logger = getLogger(__name__)
|
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
# TODO Question, is this the correct summing behavior for Peru?
|
self.structure_type = self.env.ref('l10n_pe_hr_payroll.structure_type_employee')
|
||||||
self.env['ir.config_parameter'].set_param('hr_payroll.payslip.sum_behavior', 'date_to')
|
self.structure = self.env.ref('l10n_pe_hr_payroll.hr_payroll_structure')
|
||||||
self.structure_type_id = self.ref('l10n_pe_hr_payroll.structure_type_employee')
|
self.structure_type.default_struct_id = self.structure
|
||||||
self.resource_calendar_id = self.ref('resource.resource_calendar_std')
|
# self.debug = True
|
||||||
|
self._log('PE structue_type %s %s and structure %s %s' % (self.structure_type, self.structure_type.name, self.structure, self.structure.name))
|
||||||
float_info = sys_float_info
|
self.country_pe = self.env.ref('base.pe')
|
||||||
|
|
||||||
def float_round(self, value, digits):
|
|
||||||
return odoo_float_round(value, digits)
|
|
||||||
|
|
||||||
_payroll_digits = -1
|
|
||||||
|
|
||||||
@property
|
|
||||||
def payroll_digits(self):
|
|
||||||
if self._payroll_digits == -1:
|
|
||||||
self._payroll_digits = self.env['decimal.precision'].precision_get('Payroll')
|
|
||||||
return self._payroll_digits
|
|
||||||
|
|
||||||
def _log(self, message):
|
|
||||||
if self.debug:
|
|
||||||
self._logger.warn(message)
|
|
||||||
|
|
||||||
def _createEmployee(self):
|
def _createEmployee(self):
|
||||||
return self.env['hr.employee'].create({
|
employee = super()._createEmployee()
|
||||||
'birthday': '1985-03-14',
|
employee.country_id = self.country_pe
|
||||||
'country_id': self.ref('base.pe'),
|
return employee
|
||||||
'department_id': self.ref('hr.dep_rd'),
|
|
||||||
'gender': 'male',
|
|
||||||
'name': 'Jared'
|
|
||||||
})
|
|
||||||
|
|
||||||
def _createContract(self, employee, **kwargs):
|
def _createContract(self, employee, **kwargs):
|
||||||
if not 'schedule_pay' in kwargs:
|
if not 'schedule_pay' in kwargs:
|
||||||
kwargs['schedule_pay'] = 'monthly'
|
kwargs['schedule_pay'] = 'monthly'
|
||||||
schedule_pay = kwargs['schedule_pay']
|
|
||||||
config_model = self.env['hr.contract.pe_payroll_config']
|
config_model = self.env['hr.contract.pe_payroll_config']
|
||||||
contract_model = self.env['hr.contract']
|
schedule_pay = kwargs['schedule_pay']
|
||||||
config_values = {
|
config_values = {
|
||||||
'name': 'Test Config Values',
|
'name': 'Test Config Values',
|
||||||
'employee_id': employee.id,
|
'employee_id': employee.id,
|
||||||
@@ -77,11 +45,11 @@ class TestPePayslip(common.TransactionCase):
|
|||||||
if hasattr(config_model, key):
|
if hasattr(config_model, key):
|
||||||
config_values[key] = val
|
config_values[key] = val
|
||||||
found = True
|
found = True
|
||||||
if hasattr(contract_model, key):
|
if hasattr(self.contract_model, key):
|
||||||
contract_values[key] = val
|
contract_values[key] = val
|
||||||
found = True
|
found = True
|
||||||
if not found:
|
if not found:
|
||||||
self._logger.warn('cannot locate attribute names "%s" on contract' % (key, ))
|
self._logger.warning('cannot locate attribute names "%s" on hr.contract().' % (key, ))
|
||||||
|
|
||||||
# PE Payroll Config Defaults Should be set on the Model
|
# PE Payroll Config Defaults Should be set on the Model
|
||||||
if 'date_hired' not in config_values:
|
if 'date_hired' not in config_values:
|
||||||
@@ -89,68 +57,9 @@ class TestPePayslip(common.TransactionCase):
|
|||||||
config = config_model.create(config_values)
|
config = config_model.create(config_values)
|
||||||
contract_values['pe_payroll_config_id'] = config.id
|
contract_values['pe_payroll_config_id'] = config.id
|
||||||
|
|
||||||
# Some Basic Defaults
|
self._get_contract_defaults(contract_values)
|
||||||
if not contract_values.get('state'):
|
contract = self.contract_model.create(contract_values)
|
||||||
contract_values['state'] = 'open' # Running
|
|
||||||
if not contract_values.get('structure_type_id'):
|
|
||||||
contract_values['structure_type_id'] = self.structure_type_id
|
|
||||||
if not contract_values.get('date_start'):
|
|
||||||
contract_values['date_start'] = '2016-01-01'
|
|
||||||
if not contract_values.get('date_end'):
|
|
||||||
contract_values['date_end'] = '2030-12-31'
|
|
||||||
if not contract_values.get('resource_calendar_id'):
|
|
||||||
contract_values['resource_calendar_id'] = self.resource_calendar_id
|
|
||||||
|
|
||||||
# Compatibility with earlier Odoo versions
|
# Compatibility with Odoo 14
|
||||||
if not contract_values.get('journal_id') and hasattr(contract_model, 'journal_id'):
|
|
||||||
try:
|
|
||||||
contract_values['journal_id'] = self.env['account.journal'].search([('type', '=', 'general')], limit=1).id
|
|
||||||
except KeyError:
|
|
||||||
# Accounting not installed
|
|
||||||
pass
|
|
||||||
|
|
||||||
contract = contract_model.create(contract_values)
|
|
||||||
|
|
||||||
# Compatibility with Odoo 13
|
|
||||||
contract.structure_type_id.default_struct_id.schedule_pay = schedule_pay
|
contract.structure_type_id.default_struct_id.schedule_pay = schedule_pay
|
||||||
return contract
|
return contract
|
||||||
|
|
||||||
def _createPayslip(self, employee, date_from, date_to):
|
|
||||||
slip = self.env['hr.payslip'].create({
|
|
||||||
'name': 'Test %s From: %s To: %s' % (employee.name, date_from, date_to),
|
|
||||||
'employee_id': employee.id,
|
|
||||||
'date_from': date_from,
|
|
||||||
'date_to': date_to
|
|
||||||
})
|
|
||||||
slip._onchange_employee()
|
|
||||||
slip._onchange_worked_days_inputs()
|
|
||||||
self.assertTrue(slip.contract_id)
|
|
||||||
return slip
|
|
||||||
|
|
||||||
def _getCategories(self, payslip):
|
|
||||||
categories = defaultdict(float)
|
|
||||||
for line in payslip.line_ids:
|
|
||||||
self._log(' line code: ' + str(line.code) +
|
|
||||||
' category code: ' + line.category_id.code +
|
|
||||||
' total: ' + str(line.total) +
|
|
||||||
' rate: ' + str(line.rate) +
|
|
||||||
' amount: ' + str(line.amount))
|
|
||||||
category_id = line.category_id
|
|
||||||
category_code = line.category_id.code
|
|
||||||
while category_code:
|
|
||||||
categories[category_code] += line.total
|
|
||||||
category_id = category_id.parent_id
|
|
||||||
category_code = category_id.code
|
|
||||||
return categories
|
|
||||||
|
|
||||||
def _getRules(self, payslip):
|
|
||||||
rules = defaultdict(float)
|
|
||||||
for line in payslip.line_ids:
|
|
||||||
rules[line.code] += line.total
|
|
||||||
return rules
|
|
||||||
|
|
||||||
def assertPayrollEqual(self, first, second):
|
|
||||||
self.assertAlmostEqual(first, second, self.payroll_digits)
|
|
||||||
|
|
||||||
def assertPayrollAlmostEqual(self, first, second):
|
|
||||||
self.assertAlmostEqual(first, second, self.payroll_digits-1)
|
|
||||||
|
|||||||
Reference in New Issue
Block a user