main.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.addons.website.controllers.main import Website as WebsiteBase
  4. from odoo.http import request
  5. class Website(WebsiteBase):
  6. """
  7. Extend Website controller to redirect helpdesk collaborators
  8. to the tickets dashboard after login.
  9. """
  10. def _login_redirect(self, uid, redirect=None):
  11. """
  12. Redirect helpdesk collaborators to dashboard after login.
  13. For other users, use default behavior.
  14. """
  15. # If there's an explicit redirect, respect it
  16. if redirect:
  17. return super()._login_redirect(uid, redirect=redirect)
  18. # Check if user is portal and collaborator in helpdesk team
  19. # Only check when login_success is True (after successful login)
  20. if not redirect and request.params.get('login_success'):
  21. try:
  22. user = request.env['res.users'].browse(uid)
  23. # Only check for portal users (not internal users)
  24. if user and user._is_portal():
  25. # Check if helpdesk_extras is available
  26. if 'helpdesk_extras' in request.env.registry._init_modules:
  27. partner = user.partner_id.commercial_partner_id
  28. # Check if user is a collaborator in any helpdesk team
  29. is_collaborator = (
  30. request.env["helpdesk.team.collaborator"]
  31. .sudo()
  32. .search_count([("partner_id", "=", partner.id)])
  33. > 0
  34. )
  35. if is_collaborator:
  36. # Set redirect to tickets dashboard
  37. redirect = '/my/tickets-dashboard'
  38. except Exception:
  39. # If any error occurs, fall back to default behavior
  40. # (e.g., helpdesk_extras not installed, model not available, etc.)
  41. pass
  42. # Call parent with redirect (may be None or '/my/tickets-dashboard')
  43. return super()._login_redirect(uid, redirect=redirect)