feat: prioritize company named OT when setting default company for portal users
This commit is contained in:
parent
5da11587d2
commit
21425a5cbf
@ -7,8 +7,10 @@ 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
|
||||
active_company = self.env['res.company'].search([('active', '=', True)], limit=1)
|
||||
# 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
|
||||
default['company_ids'] = [(6, 0, [active_company.id])]
|
||||
@ -17,7 +19,9 @@ 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([('active', '=', True)], limit=1)
|
||||
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:
|
||||
is_portal = False
|
||||
@ -46,7 +50,9 @@ 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([('active', '=', True)], limit=1)
|
||||
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
|
||||
if 'company_ids' not in vals:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user