[英]System redirected to same login page after login in Odoo12
我正在开发 Odoo12。 当我登录 odoo 时,它会将我重定向到同一个登录页面和所有可用的登录选项。 因此,问题与重定向有关。 我已经测试了代码并得到了 request.params['login_success'] 在打印中显示 'false' 值。 我的 python 代码如下。
@http.route(website=True, auth="public")
def web_login(self, redirect=None, *args, **kw):
response = super(CustomAuthSignupHome, self).web_login(redirect=redirect, *args, **kw)
print('Loginnn', request.params['login_success'])
if not redirect and request.params['login_success']:
user = request.env['res.users'].browse(request.uid)
if user.has_group('base.group_user'):
if user.partner_id.company_type == 'company':
redirect = '/dashboard'
else:
redirect = b'/web?' + request.httprequest.query_string
return http.redirect_with_hash(redirect)
return response
因此,任何人都可以提出解决此问题的方法。
提前致谢。
问题解决了。 错过了重定向的其他条件
@http.route(website=True, auth="public")
def web_login(self, redirect=None, *args, **kw):
response = super(CustomAuthSignupHome, self).web_login(redirect=redirect, *args, **kw)
if not redirect and request.params['login_success']:
user = request.env['res.users'].browse(request.uid)
if user.has_group('base.group_user'):
if user.partner_id.company_type == 'company':
redirect = '/dashboard'
else:
redirect = b'/web?' + request.httprequest.query_string
else:
redirect = '/my/account'
return http.redirect_with_hash(redirect)
return response
您可以创建一个继承自 res.user 的 model 并使用计算修改 action_id。
class InheritResUsers(models.Model):
_name = 'res.users'
_inherit = ['res.users']
# Nouveaux champs
action_id = fields.Many2one('ir.actions.actions', string='Home Action', compute='get_home_page')
def get_home_page(self):
for project in self:
# we position ourselves in the ir.actions.act_window model
tasks = self.env['ir.actions.act_window']
#we search for the specific view by using the name and une xml_id
task_ids = tasks.search(
[['xml_id', '=', ' project.open_view_project_all'], ['name', '=', 'Projects']])
for task in task_ids: # Browse the table by adding the page id to the inherited action_id field
self.action_id=task.id
InheritResUsers()
在这里,我重定向到我的模块的主页。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.