Skip to content
Permalink
Browse files

[IMP] hr_payroll: Use the structure type on contract instead of struc…

…ture

For usability purposes, it's better to set a structure type
on a contract (eg: CP200: Belgian Employee) instead of having
to choose between 'Belgian Salary', 'Double holidays', ...
  • Loading branch information...
tivisse committed Mar 15, 2019
1 parent 27a613a commit f62258e93426b796e3dff932c6565df4ddefff6c
@@ -20,11 +20,10 @@
</record>

<!-- Salary Structure -->

<record id="structure_002" model="hr.payroll.structure">
<field name="code">MEGG</field>
<field name="name">Marketing Executive for Gilles Gravie</field>
<field name="type_id" ref="structure_type_employee"/>
<field name="regular_pay" eval="True"/>
</record>

<!-- Salary Rules for Marketing Executive for Gilles Gravie-->
@@ -113,7 +112,7 @@
<field name="name">Marketing Executive Contract</field>
<field name="date_start" eval="time.strftime('%Y-%m')+'-1'"/>
<field name="date_end" eval="time.strftime('%Y')+'-12-31'"/>
<field name="struct_id" ref="hr_payroll.structure_002"/>
<field name="structure_type_id" ref="hr_payroll.structure_type_employee"/>
<field name="employee_id" ref="hr_employee_payroll"/>
<field name="notes">Default contract for marketing executives</field>
<field eval="4000.0" name="wage"/>
@@ -124,7 +123,7 @@
<field name="name">Contract For Gilles Gravie</field>
<field name="date_start" eval="time.strftime('%Y-%m')+'-1'"/>
<field name="date_end" eval="time.strftime('%Y')+'-12-31'"/>
<field name="struct_id" ref="hr_payroll.structure_002"/>
<field name="structure_type_id" ref="hr_payroll.structure_type_employee"/>
<field name="employee_id" ref="hr.employee_qdp"/>
<field name="notes">This is Gilles Gravie's contract</field>
<field eval="5000.0" name="wage"/>
@@ -134,7 +133,7 @@
<field name="name">Contract For Mitchell Admin</field>
<field name="date_start" eval="time.strftime('%Y-%m')+'-1'"/>
<field name="date_end" eval="time.strftime('%Y')+'-12-31'"/>
<field name="struct_id" ref="hr_payroll.structure_002"/>
<field name="structure_type_id" ref="hr_payroll.structure_type_employee"/>
<field name="employee_id" ref="hr.employee_admin"/>
<field name="notes">This is Mitchell Admin's contract</field>
<field eval="5500.0" name="wage"/>
@@ -9,8 +9,7 @@ class HrContract(models.Model):
_inherit = 'hr.contract'
_description = 'Employee Contract'

struct_id = fields.Many2one('hr.payroll.structure', string='Salary Structure')
structure_type_id = fields.Many2one(related='struct_id.type_id')
structure_type_id = fields.Many2one('hr.payroll.structure.type', string="Salary Structure Type")
schedule_pay = fields.Selection([
('monthly', 'Monthly'),
('quarterly', 'Quarterly'),
@@ -30,12 +29,12 @@ class HrContract(models.Model):
def _check_contracts(self):
self._get_leaves()._check_contracts()

@api.onchange('struct_id')
def _onchange_struct_id(self):
if self.struct_id.type_id.default_schedule_pay:
self.schedule_pay = self.struct_id.type_id.default_schedule_pay
if self.struct_id.type_id.default_resource_calendar_id:
self.resource_calendar_id = self.struct_id.type_id.default_resource_calendar_id
@api.onchange('structure_type_id')
def _onchange_structure_type_id(self):
if self.structure_type_id.default_schedule_pay:
self.schedule_pay = self.structure_type_id.default_schedule_pay
if self.structure_type_id.default_resource_calendar_id:
self.resource_calendar_id = self.structure_type_id.default_resource_calendar_id

@api.multi
def _get_leaves(self):
@@ -254,10 +254,10 @@ def onchange_employee(self):
if not self.contract_id: # Add a default contract if not already defined
contracts = employee._get_contracts(date_from, date_to)

if not contracts or not contracts[0].struct_id:
if not contracts or not contracts[0].structure_type_id.default_struct_id:
return
self.contract_id = contracts[0]
self.struct_id = contracts[0].struct_id
self.struct_id = contracts[0].structure_type_id.default_struct_id


#computation of the salary worked days
@@ -49,24 +49,19 @@ def _get_default_rule_ids(self):
]

name = fields.Char(required=True)
code = fields.Char(string='Reference', required=True)
type_id = fields.Many2one('hr.payroll.structure.type', default=lambda self: self.env.ref('hr_payroll.structure_type_employee', raise_if_not_found=False))
country_id = fields.Many2one('res.country', string='Country')
type_id = fields.Many2one(
'hr.payroll.structure.type', required=True,
default=lambda self: self.env.ref('hr_payroll.structure_type_employee', raise_if_not_found=False))
country_id = fields.Many2one('res.country', string='Country', default=lambda self: self.env.user.company_id.country_id)
note = fields.Text(string='Description')
rule_ids = fields.One2many(
'hr.salary.rule', 'struct_id',
string='Salary Rules', default=_get_default_rule_ids)
report_id = fields.Many2one('ir.actions.report',
string="Report", required=True, domain="[('model','=','hr.payslip'),('report_type','=','qweb-pdf')]", default=_get_default_report_id)
string="Report", domain="[('model','=','hr.payslip'),('report_type','=','qweb-pdf')]", default=_get_default_report_id)
payslip_name = fields.Char(string="Payslip Name", translate=True,
help="Name to be set on a payslip. Example: 'End of the year bonus'. If not set, the default value is 'Salary Slip'")

@api.multi
@api.returns('self', lambda value: value.id)
def copy(self, default=None):
self.ensure_one()
default = dict(default or {}, code=_("%s (copy)") % (self.code))
return super(HrPayrollStructure, self).copy(default)
regular_pay = fields.Boolean("Regular Pay", help="Check this option if this structure is the common one")


class HrPayrollStructureType(models.Model):
@@ -85,7 +80,16 @@ class HrPayrollStructureType(models.Model):
], string='Default Scheduled Pay', default='monthly',
help="Defines the frequency of the wage payment.")
default_resource_calendar_id = fields.Many2one(
'resource.calendar', 'Default Working Hours')
'resource.calendar', 'Default Working Hours',
default=lambda self: self.env.user.company_id.resource_calendar_id)
struct_ids = fields.One2many('hr.payroll.structure', 'type_id', string="Structures")
default_struct_id = fields.Many2one('hr.payroll.structure', compute='_compute_default_struct_id')

def _compute_default_struct_id(self):
for structure_type in self:
sorted_structures = sorted(structure_type.struct_ids, key=lambda struct: struct.regular_pay, reverse=True)
structure_type.default_struct_id = sorted_structures[0] if sorted_structures else False


class HrContributionRegister(models.Model):
_name = 'hr.contribution.register'
@@ -124,7 +128,7 @@ class HrSalaryRule(models.Model):
code = fields.Char(required=True,
help="The code of salary rules can be used as reference in computation of other rules. "
"In that case, it is case sensitive.")
struct_id = fields.Many2one('hr.payroll.structure', string="Salary Structure")
struct_id = fields.Many2one('hr.payroll.structure', string="Salary Structure", required=True)
sequence = fields.Integer(required=True, index=True, default=5,
help='Use to arrange calculation sequence')
quantity = fields.Char(default='1.0',
@@ -28,13 +28,18 @@ def setUp(self):
'department_id': self.ref('hr.dep_rd')
})

self.structure_type = self.env['hr.payroll.structure.type'].create({
'name': 'Test - Developer',
})

# I create a salary structure for "Software Developer"
self.developer_pay_structure = self.env['hr.payroll.structure'].create({
'name': 'Salary Structure for Software Developer',
'code': 'SD',
'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)],
'type_id': self.structure_type.id,
'regular_pay': True,
})

# I create a contract for "Richard"
@@ -44,7 +49,7 @@ def setUp(self):
'name': 'Contract for Richard',
'wage': 5000.0,
'employee_id': self.richard_emp.id,
'struct_id': self.developer_pay_structure.id,
'structure_type_id': self.structure_type.id,
})

self.work_entry_type_leave = self.env['hr.work.entry.type'].create({
@@ -91,7 +96,7 @@ def setUp(self):
'resource_calendar_id': self.calendar_40h.id,
'wage': 5000.0,
'employee_id': self.richard_emp.id,
'struct_id': self.developer_pay_structure.id,
'structure_type_id': self.structure_type.id,
'state': 'close',
})

@@ -102,6 +107,6 @@ def setUp(self):
'resource_calendar_id': self.calendar_35h.id,
'wage': 5000.0,
'employee_id': self.richard_emp.id,
'struct_id': self.developer_pay_structure.id,
'structure_type_id': self.structure_type.id,
'state': 'open',
})
@@ -98,7 +98,7 @@ def test_create_contract_in_leave(self):
'resource_calendar_id': self.calendar_40h.id,
'wage': 5000.0,
'employee_id': self.richard_emp.id,
'struct_id': self.developer_pay_structure.id,
'structure_type_id': self.structure_type.id,
'state': 'open',
})

@@ -25,7 +25,7 @@ def setUp(self):
'resource_calendar_id': self.resource_calendar_id.id,
'wage': 1000,
'employee_id': self.richard_emp.id,
'struct_id': self.developer_pay_structure.id,
'structure_type_id': self.structure_type.id,
'state': 'open',
})
self.richard_emp.resource_calendar_id = self.resource_calendar_id
@@ -9,8 +9,7 @@
<xpath expr="//field[@name='reported_to_secretariat']" position="before">
<field name="company_id" groups="base.group_multi_company"/>
<field name="currency_id" invisible="1"/>
<field name="struct_id" required="1"/>
<field name="structure_type_id" readonly="1"/>
<field name="structure_type_id" required="1"/>
</xpath>
<xpath expr="//field[@name='resource_calendar_id']" position="after">
<field name="schedule_pay"/>
@@ -9,9 +9,9 @@
<tree string="Employee Function">
<field name="name"/>
<field name="type_id" invisible="1"/>
<field name="code"/>
<field name="rule_ids"/>
<field name="country_id" options="{'no_create': True}"/>
<field name="regular_pay"/>
</tree>
</field>
</record>
@@ -29,11 +29,6 @@
<strong><field name="name"/></strong>
</div>
</div>
<div class="row">
<div class="col-12">
<span>Code: <field name="code"/></span>
</div>
</div>
</div>
</t>
</templates>
@@ -46,7 +41,7 @@
<field name="model">hr.payroll.structure</field>
<field name="arch" type="xml">
<search string="Payroll Structures">
<field name="name" string="Payroll Structures" filter_domain="['|',('name','ilike',self),('code','ilike',self)]"/>
<field name="name" string="Structure Name"/>
<group col="8" colspan="4" expand="0" string="Group By">
<filter string="Structure Type" name="group_by_type_id" context="{'group_by': 'type_id'}"/>
</group>
@@ -62,9 +57,9 @@
<sheet>
<group name="salary_details" col="4">
<field name="name"/>
<field name="code"/>
<field name="report_id"/>
<field name="type_id"/>
<field name="regular_pay"/>
<field name="country_id" options="{'no_create': True}"/>
</group>
<notebook colspan="4">
@@ -50,7 +50,7 @@ def compute_sheet(self):
for contract in employee._get_contracts(payslip_run.date_start, payslip_run.date_end, states=['open', 'pending', 'close']):
values.update({
'contract_id': contract.id,
'struct_id': contract.struct_id.id,
'struct_id': contract.structure_type_id.default_struct_id.id,
})
payslip = self.env['hr.payslip'].new(values)
payslip.onchange_employee()
@@ -50,7 +50,7 @@ def setUp(self):
'name': 'Contract for John',
'wage': 5000.0,
'employee_id': self.hr_employee_john.id,
'struct_id': self.env.ref('hr_payroll.structure_002').id,
'structure_type_id': self.env.ref('l10n_be_hr_payroll.structure_type_employee_cp200').id,
'journal_id': self.ref('hr_payroll_account.expenses_journal'),
})

@@ -5,8 +5,7 @@

<!-- Salary Structure -->
<record id="hr_payroll_structure_cp200_double_holiday" model="hr.payroll.structure">
<field name="code">CP 200 DH</field>
<field name="name">Double Holidays Belgian Employee</field>
<field name="name">CP200: Double Holidays</field>
<field name="country_id" ref="base.be"/>
<field name="report_id" ref="l10n_be_hr_payroll.action_report_double_holiday_13th_month"/>
<field name="payslip_name">Double Holidays Slip</field>
@@ -5,10 +5,10 @@

<!-- Salary Structure -->
<record id="hr_payroll_structure_cp200_employee_salary" model="hr.payroll.structure">
<field name="code">CP 200</field>
<field name="name">Belgian Employee</field>
<field name="name">CP200: Monthly Pay</field>
<field name="country_id" ref="base.be"/>
<field name="type_id" ref="l10n_be_hr_payroll.structure_type_employee_cp200"/>
<field name="regular_pay" eval="True"/>
</record>

<!-- Salary Rules -->
@@ -4,8 +4,7 @@
<data noupdate="0">
<!-- Salary Structure -->
<record id="hr_payroll_structure_cp200_thirteen_month" model="hr.payroll.structure">
<field name="code">CP 200 EOYB</field>
<field name="name">13th Month</field>
<field name="name">CP200: 13th Month</field>
<field name="country_id" ref="base.be"/>
<field name="report_id" ref="l10n_be_hr_payroll.action_report_double_holiday_13th_month"/>
<field name="payslip_name">13th Month Slip</field>
@@ -2,6 +2,7 @@
<odoo>
<record id="structure_type_employee_cp200" model="hr.payroll.structure.type">
<field name="name">CP200: Belgian Employee</field>
<field name="default_resource_calendar_id" ref="resource.resource_calendar_std_38h"/>
</record>

<!-- CONTRIBUTION REGISTERS -->
@@ -11,9 +11,7 @@
""",

'auto_install': True,
'data':[
'data/l10n_be_hr_payroll_account_data.xml',
],
'data':[],
'demo':['data/l10n_be_hr_payroll_account_demo.xml'],
'post_init_hook': '_set_accounts',
}

This file was deleted.

Oops, something went wrong.
@@ -3,11 +3,11 @@
<!-- Employee Contract -->

<record id="hr_contract.hr_contract_admin" model="hr.contract">
<field name="struct_id" ref="hr_payroll.structure_002"/>
<field name="structure_type_id" ref="l10n_be_hr_payroll.structure_type_employee_cp200"/>
</record>

<record id="hr_contract.hr_contract_qdp" model="hr.contract">
<field name="struct_id" ref="hr_payroll.structure_002"/>
<field name="structure_type_id" ref="l10n_be_hr_payroll.structure_type_employee_cp200"/>
</record>
</odoo>

@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="structure_type_employee_fr_cadre" model="hr.payroll.structure.type">
<field name="name">FR: Employé Cadre</field>
</record>

<!-- Salary Structure -->
<record id="hr_payroll_salary_structure_employe_cadre" model="hr.payroll.structure">
<field name="code">Fr-C</field>
<field name="name">Employe cadre</field>
<field name="name">Employé cadre</field>
<field name="country_id" ref="base.fr"/>
<field name="structure_type_id" ref="structure_type_employee_fr_cadre"/>
<field name="regular_pay" eval="True"/>
</record>

<!-- HR SALARY RULES-->
@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="structure_type_employee_fr_non_cadre" model="hr.payroll.structure.type">
<field name="name">FR: Employé Cadre</field>
</record>

<!-- Salary Structure -->
<record id="hr_payroll_salary_structure_employe_non_cadre" model="hr.payroll.structure">
<field name="code">Fr-NC</field>
<field name="name">Employe non-cadre</field>
<field name="country_id" ref="base.fr"/>
<field name="structure_type_id" ref="structure_type_employee_fr_non_cadre"/>
<field name="regular_pay" eval="True"/>
</record>

<!-- HR SALARY RULES-->
@@ -6,7 +6,7 @@
<field name="priority">20</field>
<field name="inherit_id" ref="hr_payroll.hr_contract_form_inherit"/>
<field name="arch" type="xml">
<field name="struct_id" position="after">
<field name="structure_type_id" position="after">
<field name="qualif"/>
<field name="niveau"/>
<field name="coef"/>
Oops, something went wrong.

0 comments on commit f62258e

Please sign in to comment.
You can’t perform that action at this time.