[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.
This commit is contained in:
@@ -82,29 +82,6 @@
|
||||
<field name="sequence" eval="16"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_salary_rule_sales_commission" model="hr.salary.rule">
|
||||
<field name="amount_select">code</field>
|
||||
<field name="code">SALE</field>
|
||||
<field name="category_id" ref="hr_payroll.ALW"/>
|
||||
<field name="name">Get 1% of sales</field>
|
||||
<field name="sequence" eval="17"/>
|
||||
<field name="amount_python_compute">result = ((inputs.SALEURO and inputs.SALEURO.amount) + (inputs.SALASIA and inputs.SALASIA.amount)) * 0.01</field>
|
||||
</record>
|
||||
|
||||
<!-- Rule Inputs -->
|
||||
|
||||
<record id="hr_rule_input_sale_a" model="hr.rule.input">
|
||||
<field name="code">SALEURO</field>
|
||||
<field name="name">Sales to Europe</field>
|
||||
<field name="input_id" ref="hr_salary_rule_sales_commission"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_rule_input_sale_b" model="hr.rule.input">
|
||||
<field name="code">SALASIA</field>
|
||||
<field name="name">Sales to Asia</field>
|
||||
<field name="input_id" ref="hr_salary_rule_sales_commission"/>
|
||||
</record>
|
||||
|
||||
<!-- Salary Structure -->
|
||||
|
||||
<record id="structure_001" model="hr.payroll.structure">
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
@@ -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"
|
||||
|
||||
@@ -346,14 +346,6 @@
|
||||
<separator string="Children Definition"/>
|
||||
<field name="child_ids"/>
|
||||
</page>
|
||||
<page name="inputs" string="Inputs">
|
||||
<field name="input_ids" mode="tree">
|
||||
<tree string="Input Data" editable="bottom">
|
||||
<field name="name"/>
|
||||
<field name="code"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
<page name="description" string="Description">
|
||||
<field name="note"/>
|
||||
</page>
|
||||
|
||||
@@ -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')
|
||||
])],
|
||||
})
|
||||
|
||||
|
||||
@@ -518,65 +518,4 @@ or - (contract.wage * 0.12))</field>
|
||||
<field name="appears_on_payslip" eval="False"/>
|
||||
<field name="note">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.</field>
|
||||
</record>
|
||||
|
||||
<!-- Rule Inputs -->
|
||||
|
||||
<record id="hr_rule_input_performance" model="hr.rule.input">
|
||||
<field name="code">PERF</field>
|
||||
<field name="name">Performance of Employee</field>
|
||||
<field name="input_id" ref="hr_salary_rule_performance"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_rule_input_bonus" model="hr.rule.input">
|
||||
<field name="code">BNS</field>
|
||||
<field name="name">Bonus of Employee</field>
|
||||
<field name="input_id" ref="hr_salary_rule_bonus"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_rule_input_arrears" model="hr.rule.input">
|
||||
<field name="code">ARS</field>
|
||||
<field name="name">Arrears</field>
|
||||
<field name="input_id" ref="hr_salary_rule_arrears"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_rule_input_le" model="hr.rule.input">
|
||||
<field name="code">LE</field>
|
||||
<field name="name">Leave Encashment</field>
|
||||
<field name="input_id" ref="hr_salary_rule_le"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_rule_input_journals" model="hr.rule.input">
|
||||
<field name="code">PJ</field>
|
||||
<field name="name">Periodical Journals</field>
|
||||
<field name="input_id" ref="hr_salary_rule_journals"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_rule_input_telephone" model="hr.rule.input">
|
||||
<field name="code">TR</field>
|
||||
<field name="name">Telephone Reimbursement</field>
|
||||
<field name="input_id" ref="hr_salary_rule_telephone"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_rule_input_car" model="hr.rule.input">
|
||||
<field name="code">CEI</field>
|
||||
<field name="name">Car Expenses</field>
|
||||
<field name="input_id" ref="hr_payroll_rule_car"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_rule_input_internet" model="hr.rule.input">
|
||||
<field name="code">IE</field>
|
||||
<field name="name">Internet Expence</field>
|
||||
<field name="input_id" ref="hr_salary_rule_internet"/>
|
||||
</record>
|
||||
|
||||
<record id="hr_rule_input_leave_avail" model="hr.rule.input">
|
||||
<field name="code">LAI</field>
|
||||
<field name="name">Leave Availed</field>
|
||||
<field name="input_id" ref="hr_payslip_rule_dla"/>
|
||||
</record>
|
||||
<record id="hr_rule_input_medical" model="hr.rule.input">
|
||||
<field name="code">MR</field>
|
||||
<field name="name">Medical Reimbursement</field>
|
||||
<field name="input_id" ref="hr_salary_rule_medical"/>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user