コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
8700 ビュー

Hi Community,

I want to redirect the company(Internal User) to website home page and individual(internal user) to the backend. Now, Odoo redirects the internal user to backend. So, how to conditional redirect work?

ill find code related to it and try to coditional sign in, but didn't get expected result.

<template id="web.login" name="Login">
<t t-call="web.login_layout">
<form class="oe_login_form" role="form" t-attf-action="/web/login{{ '?debug' if debug else '' }}"
method="post" onsubmit="this.action = this.action + location.hash">
.
.
.
<div t-attf-class="clearfix oe_login_buttons text-center mb-1 {{'pt-2' if form_small else 'pt-3'}}">

<button type="submit" class="btn btn-primary btn-block">Sign in44</button>
<t t-if="debug">
<button type="submit" name="redirect" value="/web/become" class="btn btn-link btn-sm btn-block">
Log in as superuser
</button>
</t>
<div class="o_login_auth"/>
</div>
<t t-if="user_id.partner_id.company_type == 'company'">
<input type="hidden" name="redirect" value="/"/>
</t>
<t t-if="user_id.partner_id.company_type != 'company'">
<input type="hidden" name="redirect" t-att-value="redirect"/>
</t>
</form>
</t>
</template>

Thanks in advance.

アバター
破棄
最善の回答

Hi,

You can make necessary changes inside the web_login function. Here in this function you can see the redirection is done by checking the user group, so you can use the same function and do as per your need.

@http.route(website=True, auth="public")
def web_login(self, redirect=None, *args, **kw):
response = super(Website, self).web_login(redirect=redirect, *args, **kw)
if not redirect and request.params['login_success']:
if request.env['res.users'].browse(request.uid).has_group('base.group_user'):
redirect = b'/web?' + request.httprequest.query_string
else:
redirect = '/'

return http.redirect_with_hash(redirect)
return response

Thanks

アバター
破棄
著作者

Thanks Niyas. I'm making changes according to my condition and it's working.

関連投稿 返信 ビュー 活動
0
8月 19
8777
2
7月 25
6224
0
9月 22
803
2
4月 21
11865
1
4月 20
8080