From c7bbbd41c74d9c07488269f2d77c88833da5cbb1 Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Thu, 29 Nov 2018 11:52:34 +0100 Subject: [PATCH] [IMP] hr_payroll: Remove hr.rule.input model There are currently 2 models: - hr.rule.input to link some inputs to an hr.payslip.rule - hr.payslip.input to add some additional inputs on a payslip. The first model is actually there to automatically add inputs on the additional inputs on the payslip. This is problematic because these rules are always added (For example a salary reduction due to a police fine). As these inputs are always added on the payslip, the the related rules are always computed with an amount of 0. We decided to remove this mechanism for the following reasons: - If the rule is important and common, then define the needed values on the contract, and compute the rules from that. - If the rule is not so important, it should be added manually when needed. --- addons/hr_payroll/data/hr_payroll_demo.xml | 23 ------- addons/hr_payroll/models/hr_payslip.py | 44 +++---------- addons/hr_payroll/models/hr_salary_rule.py | 11 +--- .../hr_payroll/security/ir.model.access.csv | 1 - addons/hr_payroll/tests/common.py | 3 +- .../hr_payroll/views/hr_salary_rule_views.xml | 8 --- .../tests/test_hr_payroll_account.py | 1 - .../data/l10n_in_hr_payroll_data.xml | 61 ------------------- 8 files changed, 10 insertions(+), 142 deletions(-) diff --git a/addons/hr_payroll/data/hr_payroll_demo.xml b/addons/hr_payroll/data/hr_payroll_demo.xml index 34a9d091fe6..43c4bbaf6a9 100644 --- a/addons/hr_payroll/data/hr_payroll_demo.xml +++ b/addons/hr_payroll/data/hr_payroll_demo.xml @@ -82,29 +82,6 @@ - - code - SALE - - Get 1% of sales - - result = ((inputs.SALEURO and inputs.SALEURO.amount) + (inputs.SALASIA and inputs.SALASIA.amount)) * 0.01 - - - - - - SALEURO - Sales to Europe - - - - - SALASIA - Sales to Asia - - - diff --git a/addons/hr_payroll/models/hr_payslip.py b/addons/hr_payroll/models/hr_payslip.py index 51f84c60b86..d42782c3202 100644 --- a/addons/hr_payroll/models/hr_payslip.py +++ b/addons/hr_payroll/models/hr_payslip.py @@ -143,7 +143,7 @@ class HrPayslip(models.Model): def get_worked_day_lines(self, contracts, date_from, date_to): """ @param contract: Browse record of contracts - @return: returns a list of dict containing the input that should be applied for the given contract between date_from and date_to + @return: returns a list of dict containing the worked days that should be applied for the given contract between date_from and date_to """ res = [] # fill only if the contract as a working schedule linked @@ -170,25 +170,6 @@ class HrPayslip(models.Model): return res - @api.model - def get_inputs(self, contracts, date_from, date_to): - res = [] - - structures = contracts.get_all_structures() - rule_ids = structures.get_all_rules() - sorted_rule_ids = [id for id, sequence in sorted(rule_ids, key=lambda x:x[1])] - inputs = self.env['hr.salary.rule'].browse(sorted_rule_ids).mapped('input_ids') - - for contract in contracts: - for input in inputs: - input_data = { - 'name': input.name, - 'code': input.code, - 'contract_id': contract.id, - } - res += [input_data] - return res - # YTI TODO: pass recordset as argument @api.model def _get_payslip_lines(self, contracts): @@ -303,10 +284,10 @@ class HrPayslip(models.Model): contracts = employee._get_contracts(date_from, date_to) else: if contract_id: - #set the list of contract for which the input have to be filled + #set the list of contract for which the worked days have to be filled contracts = self.env['hr.contract'].browse(contract_id) else: - #if we don't give the contract, then the input to fill should be for all current contracts of the employee + #if we don't give the contract, then the worked days to fill should be for all current contracts of the employee contracts = employee._get_contracts(date_from, date_to) if not contracts: @@ -321,13 +302,9 @@ class HrPayslip(models.Model): res['value'].update({ 'struct_id': struct.id, }) - #computation of the salary input + #computation of the salary worked days worked_days_line_ids = self.get_worked_day_lines(contracts, date_from, date_to) - input_line_ids = self.get_inputs(contracts, date_from, date_to) - res['value'].update({ - 'worked_days_line_ids': worked_days_line_ids, - 'input_line_ids': input_line_ids, - }) + res['value'].update({'worked_days_line_ids': worked_days_line_ids}) return res @api.onchange('employee_id', 'date_from', 'date_to') @@ -356,18 +333,13 @@ class HrPayslip(models.Model): return self.struct_id = self.contract_id.struct_id - #computation of the salary input + #computation of the salary worked days worked_days_line_ids = self.get_worked_day_lines(contracts, date_from, date_to) worked_days_lines = self.worked_days_line_ids.browse([]) for r in worked_days_line_ids: worked_days_lines += worked_days_lines.new(r) self.worked_days_line_ids = worked_days_lines - input_line_ids = self.get_inputs(contracts, date_from, date_to) - input_lines = self.input_line_ids.browse([]) - for r in input_line_ids: - input_lines += input_lines.new(r) - self.input_line_ids = input_lines return @api.onchange('contract_id') @@ -411,7 +383,7 @@ class HrPayslipLine(models.Model): amount_fix = fields.Float(related='salary_rule_id.amount_fix', readonly=True) amount_percentage = fields.Float(related='salary_rule_id.amount_percentage', readonly=True) appears_on_payslip = fields.Boolean(related='salary_rule_id.appears_on_payslip', readonly=True) - category_id = fields.Many2one(related='salary_rule_id.category_id', readonly=True) + category_id = fields.Many2one(related='salary_rule_id.category_id', readonly=True, store=True) register_id = fields.Many2one(related='salary_rule_id.register_id', readonly=True, store=True) @api.depends('quantity', 'amount', 'rate') @@ -443,7 +415,7 @@ class HrPayslipWorkedDays(models.Model): number_of_days = fields.Float(string='Number of Days') number_of_hours = fields.Float(string='Number of Hours') contract_id = fields.Many2one('hr.contract', string='Contract', required=True, - help="The contract for which applied this input") + help="The contract for which applied this worked days") class HrPayslipInput(models.Model): diff --git a/addons/hr_payroll/models/hr_salary_rule.py b/addons/hr_payroll/models/hr_salary_rule.py index 75a899f9eca..9a6ccecf90c 100644 --- a/addons/hr_payroll/models/hr_salary_rule.py +++ b/addons/hr_payroll/models/hr_salary_rule.py @@ -135,7 +135,7 @@ class HrSalaryRule(models.Model): # rules: object containing the rules code (previously computed) # categories: object containing the computed salary rule categories (sum of amount of all rules belonging to that category). # worked_days: object containing the computed worked days - # inputs: object containing the computed inputs + # inputs: object containing the computed inputs. # Note: returned value have to be set in the variable 'result' @@ -170,7 +170,6 @@ class HrSalaryRule(models.Model): child_ids = fields.One2many('hr.salary.rule', 'parent_rule_id', string='Child Salary Rule', copy=True) register_id = fields.Many2one('hr.contribution.register', string='Contribution Register', help="Eventual third party involved in the salary payment of the employees.") - input_ids = fields.One2many('hr.rule.input', 'input_id', string='Inputs', copy=True) note = fields.Text(string='Description') @api.constrains('parent_rule_id') @@ -239,11 +238,3 @@ class HrSalaryRule(models.Model): except: raise UserError(_('Wrong python condition defined for salary rule %s (%s).') % (self.name, self.code)) - -class HrRuleInput(models.Model): - _name = 'hr.rule.input' - _description = 'Salary Rule Input' - - name = fields.Char(string='Description', required=True) - code = fields.Char(required=True, help="The code that can be used in the salary rules") - input_id = fields.Many2one('hr.salary.rule', string='Salary Rule Input', required=True) diff --git a/addons/hr_payroll/security/ir.model.access.csv b/addons/hr_payroll/security/ir.model.access.csv index 853f5ef67f5..484551f5cc4 100644 --- a/addons/hr_payroll/security/ir.model.access.csv +++ b/addons/hr_payroll/security/ir.model.access.csv @@ -8,7 +8,6 @@ access_hr_payslip_line,hr.payslip.line,model_hr_payslip_line,hr_payroll.group_hr access_hr_payslip_input_user,hr.payslip.input.user,model_hr_payslip_input,hr_payroll.group_hr_payroll_user,1,1,1,1 access_hr_payslip_worked_days_officer,hr.payslip.worked_days.officer,model_hr_payslip_worked_days,hr_payroll.group_hr_payroll_user,1,1,1,1 access_hr_payslip_run,hr.payslip.run,model_hr_payslip_run,hr_payroll.group_hr_payroll_manager,1,1,1,1 -access_hr_rule_input_officer,hr.rule.input.office,model_hr_rule_input,hr_payroll.group_hr_payroll_user,1,1,1,1 access_hr_salary_rule_user,hr.salary.rule.user,model_hr_salary_rule,hr_payroll.group_hr_payroll_user,1,1,1,1 access_hr_contract_advantage_template,hr.contract.advantage.template.user,model_hr_contract_advantage_template,hr_payroll.group_hr_payroll_user,1,1,1,1 access_hr_contract_advantage_template_hr_user,hr.contract.advantage.template.hr.user,model_hr_contract_advantage_template,hr.group_hr_user,1,0,0,0 diff --git a/addons/hr_payroll/tests/common.py b/addons/hr_payroll/tests/common.py index 29e5faa31e3..8d50dec7621 100644 --- a/addons/hr_payroll/tests/common.py +++ b/addons/hr_payroll/tests/common.py @@ -18,7 +18,6 @@ class TestPayslipBase(TransactionCase): self.prof_tax_rule_id = self.ref('hr_payroll.hr_salary_rule_professionaltax1') self.pf_rule_id = self.ref('hr_payroll.hr_salary_rule_providentfund1') self.mv_rule_id = self.ref('hr_payroll.hr_salary_rule_meal_voucher') - self.comm_rule_id = self.ref('hr_payroll.hr_salary_rule_sales_commission') # I create a new employee "Richard" self.richard_emp = self.env['hr.employee'].create({ @@ -36,7 +35,7 @@ class TestPayslipBase(TransactionCase): 'company_id': self.ref('base.main_company'), 'rule_ids': [(4, self.hra_rule_id), (4, self.conv_rule_id), (4, self.prof_tax_rule_id), (4, self.pf_rule_id), - (4, self.mv_rule_id), (4, self.comm_rule_id)], + (4, self.mv_rule_id)], }) # I create a contract for "Richard" diff --git a/addons/hr_payroll/views/hr_salary_rule_views.xml b/addons/hr_payroll/views/hr_salary_rule_views.xml index 31f11045fac..37f1c91e2d3 100644 --- a/addons/hr_payroll/views/hr_salary_rule_views.xml +++ b/addons/hr_payroll/views/hr_salary_rule_views.xml @@ -346,14 +346,6 @@ - - - - - - - - diff --git a/addons/hr_payroll_account/tests/test_hr_payroll_account.py b/addons/hr_payroll_account/tests/test_hr_payroll_account.py index f0b01a54198..202a42db0fc 100644 --- a/addons/hr_payroll_account/tests/test_hr_payroll_account.py +++ b/addons/hr_payroll_account/tests/test_hr_payroll_account.py @@ -56,7 +56,6 @@ class TestHrPayrollAccount(common.TransactionCase): self.ref('hr_payroll.hr_salary_rule_professionaltax1'), self.ref('hr_payroll.hr_salary_rule_providentfund1'), self.ref('hr_payroll.hr_salary_rule_meal_voucher'), - self.ref('hr_payroll.hr_salary_rule_sales_commission') ])], }) diff --git a/addons/l10n_in_hr_payroll/data/l10n_in_hr_payroll_data.xml b/addons/l10n_in_hr_payroll/data/l10n_in_hr_payroll_data.xml index 3860c170f5b..ee5b4367e7d 100644 --- a/addons/l10n_in_hr_payroll/data/l10n_in_hr_payroll_data.xml +++ b/addons/l10n_in_hr_payroll/data/l10n_in_hr_payroll_data.xml @@ -518,65 +518,4 @@ or - (contract.wage * 0.12)) Both the employees and employer contribute to the fund at the rate of 12% of the basic wages, dearness allowance and retaining allowance, if any, payable to employees per month. - - - - - PERF - Performance of Employee - - - - - BNS - Bonus of Employee - - - - - ARS - Arrears - - - - - LE - Leave Encashment - - - - - PJ - Periodical Journals - - - - - TR - Telephone Reimbursement - - - - - CEI - Car Expenses - - - - - IE - Internet Expence - - - - - LAI - Leave Availed - - - - MR - Medical Reimbursement - -