From 21aca47046c5765cc164c8a2ecf57e3b942b2a5c Mon Sep 17 00:00:00 2001 From: dasz Date: Thu, 20 Apr 2023 07:23:49 +0000 Subject: [PATCH] [IMP] hr_contract: add ordering option to structure types added sequence + handle for tree view and updated compute to select company's country's structure type first. task 3279050 closes odoo/odoo#119810 Related: odoo/enterprise#41190 Signed-off-by: Kevin Baptiste --- addons/hr_contract/models/hr_contract.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/addons/hr_contract/models/hr_contract.py b/addons/hr_contract/models/hr_contract.py index edeaec45b3a..ef177c6f992 100644 --- a/addons/hr_contract/models/hr_contract.py +++ b/addons/hr_contract/models/hr_contract.py @@ -23,7 +23,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") + structure_type_id = fields.Many2one('hr.payroll.structure.type', string="Salary Structure Type", compute="_compute_structure_type_id", readonly=False, store=True) employee_id = fields.Many2one('hr.employee', string='Employee', tracking=True, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]") department_id = fields.Many2one('hr.department', compute='_compute_employee_contract', store=True, readonly=False, domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", string="Department") @@ -95,23 +95,19 @@ class Contract(models.Model): contract.resource_calendar_id = contract.employee_id.resource_calendar_id contract.company_id = contract.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.depends('company_id') + def _compute_structure_type_id(self): + structure_type_id = self.env['hr.payroll.structure.type'].search([('country_id', '=', self.company_id.country_id.id)], limit=1) + if not structure_type_id: + structure_type_id = self.env['hr.payroll.structure.type'].search([('country_id', '=', False)], limit=1) + for contract in self: + contract.structure_type_id = structure_type_id @api.onchange('structure_type_id') def _onchange_structure_type_id(self): default_calendar = self.structure_type_id.default_resource_calendar_id if default_calendar and default_calendar.company_id == self.company_id: - self.resource_calendar_id = self.structure_type_id.default_resource_calendar_id + self.resource_calendar_id = default_calendar @api.constrains('employee_id', 'state', 'kanban_state', 'date_start', 'date_end') def _check_current_contract(self):