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/models | |
| 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/models')
| -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 |
3 files changed, 36 insertions, 1 deletions
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) |
