# -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo.addons.website.controllers.main import Website as WebsiteBase from odoo.http import request class Website(WebsiteBase): """ Extend Website controller to redirect helpdesk collaborators to the tickets dashboard after login. """ def _login_redirect(self, uid, redirect=None): """ Redirect helpdesk collaborators to dashboard after login. For other users, use default behavior. """ # If there's an explicit redirect, respect it if redirect: return super()._login_redirect(uid, redirect=redirect) # Check if user is portal and collaborator in helpdesk team # Only check when login_success is True (after successful login) if not redirect and request.params.get('login_success'): try: user = request.env['res.users'].browse(uid) # Only check for portal users (not internal users) if user and user._is_portal(): # Check if helpdesk_extras is available if 'helpdesk_extras' in request.env.registry._init_modules: partner = user.partner_id # Check if user is a collaborator in any helpdesk team is_collaborator = ( request.env["helpdesk.team.collaborator"] .sudo() .search_count([("partner_id", "=", partner.id)]) > 0 ) if is_collaborator: # Set redirect to tickets dashboard redirect = '/my/tickets-dashboard' except Exception: # If any error occurs, fall back to default behavior # (e.g., helpdesk_extras not installed, model not available, etc.) pass # Call parent with redirect (may be None or '/my/tickets-dashboard') return super()._login_redirect(uid, redirect=redirect)