diff options
| author | Yannick Tivisse <yti@odoo.com> | 2020-03-11 15:32:00 +0000 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2020-03-16 08:45:50 +0000 |
| commit | d77f5eb8209d5180e8607926712284486d451130 (patch) | |
| tree | 5bc3f0e98a245a1c50f9d07f0bb6825dfd6ab972 /addons/hr_contract | |
| parent | 1b3f4c91440d26e3b6ff666786e00f1aa9c5ebac (diff) | |
[IMP] hr_contract: Move payroll structure type from hr_payroll to hr_contract
Purpose
=======
Even if you don't manage your payroll using Odoo, it could interesting to
categorize your contract (CP200, ...), in case you manage several kind
of workers or employees in your company.
TaskID: 2148537
Diffstat (limited to 'addons/hr_contract')
| -rw-r--r-- | addons/hr_contract/data/hr_contract_data.xml | 19 | ||||
| -rw-r--r-- | addons/hr_contract/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/hr_contract/models/hr_contract.py | 21 | ||||
| -rw-r--r-- | addons/hr_contract/models/hr_contract_type.py | 15 | ||||
| -rw-r--r-- | addons/hr_contract/security/ir.model.access.csv | 1 | ||||
| -rw-r--r-- | addons/hr_contract/security/security.xml | 7 | ||||
| -rw-r--r-- | addons/hr_contract/views/hr_contract_views.xml | 4 |
7 files changed, 66 insertions, 2 deletions
diff --git a/addons/hr_contract/data/hr_contract_data.xml b/addons/hr_contract/data/hr_contract_data.xml index 2bd98cb17e1..56f6aabceb9 100644 --- a/addons/hr_contract/data/hr_contract_data.xml +++ b/addons/hr_contract/data/hr_contract_data.xml @@ -1,6 +1,25 @@ <?xml version="1.0" encoding="utf-8"?> <odoo> <data noupdate="1"> + <!-- Structure Type --> + <record id="structure_type_employee" model="hr.payroll.structure.type"> + <field name="name">Employee</field> + <field name="country_id" eval="False"/> + </record> + <record id="structure_type_worker" model="hr.payroll.structure.type"> + <field name="name">Worker</field> + <field name="country_id" eval="False"/> + </record> + <record id="structure_type_employee_cp200_pfi" model="hr.payroll.structure.type"> + <field name="name">CP200 PFI: Belgian Employee</field> + <field name="default_resource_calendar_id" ref="resource.resource_calendar_std_38h"/> + <field name="country_id" ref="base.be"/> + </record> + <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"/> + <field name="country_id" ref="base.be"/> + </record> <!-- Contract-related subtypes for messaging / Chatter --> <record id="mt_contract_pending" model="mail.message.subtype"> diff --git a/addons/hr_contract/models/__init__.py b/addons/hr_contract/models/__init__.py index e38ab2a4586..4c75f9fbf8a 100644 --- a/addons/hr_contract/models/__init__.py +++ b/addons/hr_contract/models/__init__.py @@ -5,3 +5,4 @@ from . import hr_employee from . import hr_contract from . import res_users from . import resource +from . import hr_contract_type diff --git a/addons/hr_contract/models/hr_contract.py b/addons/hr_contract/models/hr_contract.py index 5f5509ccfc5..492b07b372e 100644 --- a/addons/hr_contract/models/hr_contract.py +++ b/addons/hr_contract/models/hr_contract.py @@ -16,6 +16,7 @@ class Contract(models.Model): name = fields.Char('Contract Reference', required=True) active = fields.Boolean(default=True) + structure_type_id = fields.Many2one('hr.payroll.structure.type', string="Salary Structure Type") employee_id = fields.Many2one('hr.employee', string='Employee', tracking=True, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") department_id = fields.Many2one('hr.department', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", string="Department") job_id = fields.Many2one('hr.job', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", string='Job Position') @@ -40,6 +41,8 @@ class Contract(models.Model): ], string='Status', group_expand='_expand_states', copy=False, tracking=True, help='Status of the contract', default='draft') company_id = fields.Many2one('res.company', default=lambda self: self.env.company, required=True) + company_country_id = fields.Many2one('res.country', string="Company country", related='company_id.country_id', readonly=True) + """ kanban_state: * draft + green = "Incoming" state (will be set as Open once the contract has started) @@ -68,7 +71,6 @@ class Contract(models.Model): def _expand_states(self, states, domain, order): return [key for key, val in type(self).state.selection] - @api.onchange('employee_id') def _onchange_employee_id(self): if self.employee_id: @@ -77,6 +79,23 @@ class Contract(models.Model): self.resource_calendar_id = self.employee_id.resource_calendar_id self.company_id = self.employee_id.company_id + @api.onchange('company_id') + def _onchange_company_id(self): + if self.company_id: + structure_types = self.env['hr.payroll.structure.type'].search([ + '|', + ('country_id', '=', self.company_id.country_id.id), + ('country_id', '=', False)]) + if structure_types: + self.structure_type_id = structure_types[0] + elif self.structure_type_id not in structure_types: + self.structure_type_id = False + + @api.onchange('structure_type_id') + def _onchange_structure_type_id(self): + if self.structure_type_id.default_resource_calendar_id: + self.resource_calendar_id = self.structure_type_id.default_resource_calendar_id + @api.constrains('employee_id', 'state', 'kanban_state', 'date_start', 'date_end') def _check_current_contract(self): """ Two contracts in state [incoming | open | close] cannot overlap """ diff --git a/addons/hr_contract/models/hr_contract_type.py b/addons/hr_contract/models/hr_contract_type.py new file mode 100644 index 00000000000..4e25f859140 --- /dev/null +++ b/addons/hr_contract/models/hr_contract_type.py @@ -0,0 +1,15 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models + + +class HrPayrollStructureType(models.Model): + _name = 'hr.payroll.structure.type' + _description = 'Contract Type' + + name = fields.Char('Contract Type') + default_resource_calendar_id = fields.Many2one( + 'resource.calendar', 'Default Working Hours', + default=lambda self: self.env.company.resource_calendar_id) + country_id = fields.Many2one('res.country', string='Country', default=lambda self: self.env.company.country_id) diff --git a/addons/hr_contract/security/ir.model.access.csv b/addons/hr_contract/security/ir.model.access.csv index 5bdda089639..5ad33d10a92 100644 --- a/addons/hr_contract/security/ir.model.access.csv +++ b/addons/hr_contract/security/ir.model.access.csv @@ -3,3 +3,4 @@ access_hr_resource_manager,hr.employee.resource.manager,resource.model_resource_ access_hr_resource_calendar_user,hr.employee.resource.calendar.user,resource.model_resource_calendar,hr.group_hr_user,1,1,1,1
access_hr_resource_calendar_attendance_user,hr.employee.resource.calendar.attendance.user,resource.model_resource_calendar_attendance,hr.group_hr_user,1,1,1,1
access_hr_contract_manager,hr.contract.manager,model_hr_contract,hr_contract.group_hr_contract_manager,1,1,1,1
+access_hr_payroll_structure_type_hr_contract_manager,hr.payroll.structure.type.contract.manager,model_hr_payroll_structure_type,hr_contract.group_hr_contract_manager,1,1,1,1
diff --git a/addons/hr_contract/security/security.xml b/addons/hr_contract/security/security.xml index 4a3cf359d8e..2ffba623cf7 100644 --- a/addons/hr_contract/security/security.xml +++ b/addons/hr_contract/security/security.xml @@ -24,5 +24,12 @@ <field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field> </record> + <record id="ir_rule_hr_payroll_structure_type_multi_company" model="ir.rule"> + <field name="name">HR Payroll Structure Type: Multi Company</field> + <field name="model_id" ref="model_hr_payroll_structure_type"/> + <field name="global" eval="True"/> + <field name="domain_force">['|', ('country_id', '=', False), ('country_id', 'in', user.env.companies.mapped('country_id').ids)]</field> + </record> + </data> </odoo> diff --git a/addons/hr_contract/views/hr_contract_views.xml b/addons/hr_contract/views/hr_contract_views.xml index 1269d3242dd..d57a0ac08a7 100644 --- a/addons/hr_contract/views/hr_contract_views.xml +++ b/addons/hr_contract/views/hr_contract_views.xml @@ -172,8 +172,10 @@ <field name="department_id"/> <field name="job_id"/> <field name="company_id" groups="base.group_multi_company"/> + <field name="company_country_id" invisible="1"/> + <field name="structure_type_id" domain="['|', ('country_id', '=', False), ('country_id', '=', company_country_id)]"/> </group> - <group> + <group name="duration_group"> <field name="date_start"/> <field name="first_contract_date" attrs="{'invisible': ['|', ('first_contract_date', '=', False), ('first_contract_date', '=', 'date_start')]}"/> <field name="date_end"/> |
