from odoo import models, fields, api, _ class HrEmployee(models.Model): _inherit = 'hr.employee' company_ids = fields.Many2many( 'res.company', string='Branches', domain="[('parent_id', '!=', False)]", help="Branch companies this employee is associated with." ) # Overriding company_id to be computed from company_ids # This maintains compatibility with standard Odoo logic that expects a single company_id company_id = fields.Many2one( 'res.company', string='Company', compute='_compute_company_id', store=True, readonly=False, required=True, help="The primary company of the employee. Automatically set to the first branch in Branches." ) attendance_manager_id = fields.Many2one( 'res.users', domain="[('share', '=', False), ('company_ids', 'in', company_ids)]" ) @api.depends('company_ids') def _compute_company_id(self): for employee in self: if employee.company_ids: employee.company_id = employee.company_ids[0] elif not employee.company_id: # Fallback to current company if none specified employee.company_id = self.env.company