Skip to content

Commit

Permalink
[FIX] Creating a portal user for a partner in multicompany database
Browse files Browse the repository at this point in the history
Backport of odoo@7e1b0792da8
Also allow for partners that do not have a company.
  • Loading branch information
StefanRijnhart committed Jan 11, 2017
1 parent c7b730f commit 222ac1e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion addons/portal/wizard/portal_wizard.py
Expand Up @@ -140,7 +140,11 @@ def action_apply(self, cr, uid, ids, context=None):
if wizard_user.in_portal:
# create a user if necessary, and make sure it is in the portal group
if not user:
user = self._create_user(cr, SUPERUSER_ID, wizard_user, context)
if wizard_user.partner_id.company_id:
company_id = wizard_user.partner_id.company_id.id
else:
company_id = self.pool['res.users'].browse(cr, SUPERUSER_ID, uid, context=context).company_id.id
user = self._create_user(cr, SUPERUSER_ID, wizard_user, dict(context, company_id=company_id))
if (not user.active) or (portal not in user.groups_id):
user.write({'active': True, 'groups_id': [(4, portal.id)]})
# prepare for the signup process
Expand Down Expand Up @@ -177,6 +181,8 @@ def _create_user(self, cr, uid, wizard_user, context=None):
res_users = self.pool.get('res.users')
create_context = dict(context or {}, noshortcut=True) # to prevent shortcut creation
values = {
'company_id': context['company_id'],
'company_ids': [(6, 0, [context['company_id']])],
'login': extract_email(wizard_user.email),
'partner_id': wizard_user.partner_id.id,
'groups_id': [(6, 0, [])],
Expand Down

0 comments on commit 222ac1e

Please sign in to comment.