Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
8631 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

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

Powiązane posty Odpowiedzi Widoki Czynność
0
sie 19
8717
2
lip 25
6123
0
wrz 22
803
2
kwi 21
11828
1
kwi 20
7989