feat: prioritize company named OT when setting default company for portal users

This commit is contained in:
Suherdy Yacob 2026-06-13 17:41:47 +07:00
parent 5da11587d2
commit 21425a5cbf

View File

@ -7,7 +7,9 @@ class ResUsers(models.Model):
portal_template = self.env.ref('base.template_portal_user_id', raise_if_not_found=False)
if portal_template and self.id == portal_template.id:
default = default or {}
# Find first active company
# Find OT company or fallback to first active company
active_company = self.env['res.company'].search([('name', '=', 'OT')], limit=1)
if not active_company:
active_company = self.env['res.company'].search([('active', '=', True)], limit=1)
if active_company:
default['company_id'] = active_company.id
@ -17,6 +19,8 @@ class ResUsers(models.Model):
@api.model_create_multi
def create(self, vals_list):
portal_group = self.env.ref('base.group_portal', raise_if_not_found=False)
active_company = self.env['res.company'].search([('name', '=', 'OT')], limit=1)
if not active_company:
active_company = self.env['res.company'].search([('active', '=', True)], limit=1)
for vals in vals_list:
@ -46,6 +50,8 @@ class ResUsers(models.Model):
if 'company_id' in vals:
company = self.env['res.company'].browse(vals['company_id'])
if not company.active:
active_company = self.env['res.company'].search([('name', '=', 'OT')], limit=1)
if not active_company:
active_company = self.env['res.company'].search([('active', '=', True)], limit=1)
if active_company:
vals['company_id'] = active_company.id