From b517fdc19d3a3530695895757679bdafb415e6e4 Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Fri, 24 Sep 2021 11:30:42 +0200 Subject: [PATCH] [IMP] project: rename the portal form view route of project and task Before this commit, when the current user is in the '/my/projects' route and selects a project the route becomes '/my/project/'. There is no reason to change the route and then adding the id of the project. In sales order route, we keep the route and we add the id of the SO to see the portal form view of the SO selected. This commit renames the route of project and task form view to keep the same route and the same logic of SO and quotations routes for instance. task-2648955 Closes #82379 --- addons/project/controllers/portal.py | 25 ++++++++++++++----- addons/project/models/project.py | 4 +-- .../views/project_portal_templates.xml | 6 ++--- .../views/project_sharing_templates.xml | 2 +- odoo/addons/base/models/ir_http.py | 2 +- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/addons/project/controllers/portal.py b/addons/project/controllers/portal.py index b7e108713d6..98de1ef43ae 100644 --- a/addons/project/controllers/portal.py +++ b/addons/project/controllers/portal.py @@ -63,7 +63,7 @@ class ProjectCustomerPortal(CustomerPortal): # task count task_count = Task.search_count(domain) # pager - url = "/my/project/%s" % project.id + url = "/my/projects/%s" % project.id pager = portal_pager( url=url, url_args={'date_begin': date_begin, 'date_end': date_end, 'sortby': sortby, 'groupby': groupby, 'search_in': search_in, 'search': search}, @@ -146,7 +146,20 @@ class ProjectCustomerPortal(CustomerPortal): }) return request.render("project.portal_my_projects", values) - @http.route(['/my/project/'], type='http', auth="public", website=True) + @http.route(['/my/project/', + '/my/project//page/', + '/my/project//task/', + '/my/project//project_sharing'], type='http', auth="public") + def portal_project_routes_outdated(self, **kwargs): + """ Redirect the outdated routes to the new routes. """ + return request.redirect(request.httprequest.path.replace('/my/project/', '/my/projects/')) + + @http.route(['/my/task', '/my/task/page/'], type='http', auth='public') + def portal_my_task_routes_outdated(self, **kwargs): + """ Redirect the outdated routes to the new routes. """ + return request.redirect(request.httprequest.path.replace('/my/task', '/my/tasks')) + + @http.route(['/my/projects/'], type='http', auth="public", website=True) def portal_my_project(self, project_id=None, access_token=None, page=1, date_begin=None, date_end=None, sortby=None, search=None, search_in='content', groupby=None, task_id=None, **kw): try: project_sudo = self._document_check_access('project.project', project_id, access_token) @@ -195,7 +208,7 @@ class ProjectCustomerPortal(CustomerPortal): session_info['open_task_action'] = task.action_project_sharing_open_task() return session_info - @http.route("/my/project//project_sharing", type="http", auth="user", methods=['GET']) + @http.route("/my/projects//project_sharing", type="http", auth="user", methods=['GET']) def render_project_backend_view(self, project_id, task_id=None): project = request.env['project.project'].sudo().browse(project_id) if not project.exists() or not project.with_user(request.env.user)._check_project_sharing_access(): @@ -206,7 +219,7 @@ class ProjectCustomerPortal(CustomerPortal): {'session_info': self._prepare_project_sharing_session_info(project, task)}, ) - @http.route('/my/project//task/', type='http', auth='public', website=True) + @http.route('/my/projects//task/', type='http', auth='public', website=True) def portal_my_project_task(self, project_id=None, task_id=None, access_token=None, **kw): try: project_sudo = self._document_check_access('project.project', project_id, access_token) @@ -414,7 +427,7 @@ class ProjectCustomerPortal(CustomerPortal): 'grouped_tasks': grouped_tasks, 'page_name': 'task', 'default_url': '/my/tasks', - 'task_url': 'task', + 'task_url': 'tasks', 'pager': pager, 'searchbar_sortings': searchbar_sortings, 'searchbar_groupby': searchbar_groupby, @@ -433,7 +446,7 @@ class ProjectCustomerPortal(CustomerPortal): # The route should not be called if at least hr_timesheet is not installed raise MissingError(_('There is nothing to report.')) - @http.route(['/my/task/'], type='http', auth="public", website=True) + @http.route(['/my/tasks/'], type='http', auth="public", website=True) def portal_my_task(self, task_id, report_type=None, access_token=None, **kw): try: task_sudo = self._document_check_access('project.task', task_id, access_token) diff --git a/addons/project/models/project.py b/addons/project/models/project.py index 29b2dbfc3f5..3e2565c0a44 100644 --- a/addons/project/models/project.py +++ b/addons/project/models/project.py @@ -364,7 +364,7 @@ class Project(models.Model): def _compute_access_url(self): super(Project, self)._compute_access_url() for project in self: - project.access_url = '/my/project/%s' % project.id + project.access_url = f'/my/projects/{project.id}' def _compute_access_warning(self): super(Project, self)._compute_access_warning() @@ -1397,7 +1397,7 @@ class Task(models.Model): def _compute_access_url(self): super(Task, self)._compute_access_url() for task in self: - task.access_url = '/my/task/%s' % task.id + task.access_url = f'/my/tasks/{task.id}' def _compute_access_warning(self): super(Task, self)._compute_access_warning() diff --git a/addons/project/views/project_portal_templates.xml b/addons/project/views/project_portal_templates.xml index 17ea2b8d22b..f2fb8fb2edb 100644 --- a/addons/project/views/project_portal_templates.xml +++ b/addons/project/views/project_portal_templates.xml @@ -7,7 +7,7 @@ Projects
  • @@ -61,7 +61,7 @@ - + @@ -262,7 +262,7 @@