Skip to content
Browse files

[FIX] add current website to context

  • Loading branch information...
rubenseijas committed Aug 8, 2019
1 parent 2475c62 commit 1f76cbb68f97e6d6429252ec2b0ff454da29594d
@@ -1,3 +1,4 @@
from . import ir_config_parameter
from . import res_users
from . import ir_property
from . import portal_wizard
@@ -0,0 +1,61 @@
# -*- coding: utf-8 -*-

from odoo.exceptions import UserError

from odoo import api, models

class PortalWizardUser(models.TransientModel):
A model to configure users in the portal wizard for current website in current company.

_inherit = 'portal.wizard.user'

def action_apply(self):
""" From selected partners, add corresponding users to chosen portal group. It either granted
existing user, or create new one (and add it to the group) for current website in current company.
error_msg = self.get_error_messages()
if error_msg:
raise UserError("\n\n".join(error_msg))

# Change: website_id is necessary in context for a company with multi website.
# The wizard create an access for current website in current company
for wizard_user in self.sudo().with_context(active_test=False,
group_portal = wizard_user.wizard_id.portal_id
if not group_portal.is_portal:
raise UserError(_('Group %s is not a portal') %
user = wizard_user.partner_id.user_ids[0] if wizard_user.partner_id.user_ids else None
# update partner email, if a new one was introduced
if !=
# add portal group to relative user of selected partners
if wizard_user.in_portal:
user_portal = None
# create a user if necessary, and make sure it is in the portal group
if not user:
if wizard_user.partner_id.company_id:
company_id =
company_id = self.env['']._company_default_get('res.users').id
user_portal = wizard_user.sudo().with_context(company_id=company_id)._create_user()
user_portal = user
if not or group_portal not in wizard_user.user_id.groups_id:
wizard_user.user_id.write({'active': True, 'groups_id': [(4,]})
# prepare for the signup process
# remove the user (if it exists) from the portal group
if user and group_portal in user.groups_id:
# if user belongs to portal only, deactivate it
if len(user.groups_id) <= 1:
user.write({'groups_id': [(3,], 'active': False})
user.write({'groups_id': [(3,]})

0 comments on commit 1f76cbb

Please sign in to comment.
You can’t perform that action at this time.