From 150686947bc0229a239d1a1b4a31f323c553952c Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Mon, 13 Sep 2021 15:18:40 +0200 Subject: [PATCH] [FIX] project,hr_timesheet: add uom in session to use widget Before this commit, since we don't have the uom in the session, the timesheet_uom widgets does not work in project sharing feature. Because those widgets need the uom stored in the session. This commit adds the uoms needed in the session used for project sharing feature. task-2633229 closes #77156 X-original-commit: a8f27ac776e8f381cb467be3a0256b197d6e688f --- addons/hr_timesheet/controllers/project.py | 25 ++++++++++++++++++++++ addons/project/controllers/portal.py | 18 ++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/addons/hr_timesheet/controllers/project.py b/addons/hr_timesheet/controllers/project.py index cf9afc7b4c3..970ae2fdb0f 100644 --- a/addons/hr_timesheet/controllers/project.py +++ b/addons/hr_timesheet/controllers/project.py @@ -10,6 +10,31 @@ from odoo.addons.project.controllers.portal import CustomerPortal class ProjectCustomerPortal(CustomerPortal): + def _prepare_project_sharing_session_info(self, project): + session_info = super()._prepare_project_sharing_session_info(project) + + company = project.company_id + timesheet_encode_uom = company.timesheet_encode_uom_id + project_time_mode_uom = company.project_time_mode_id + session_info['user_companies']['allowed_companies'][company.id].update( + timesheet_uom_id=timesheet_encode_uom.id, + timesheet_uom_factor=project_time_mode_uom._compute_quantity( + 1.0, + timesheet_encode_uom, + round=False + ), + ) + session_info['uom_ids'] = { + uom.id: + { + 'id': uom.id, + 'name': uom.name, + 'rounding': uom.rounding, + 'timesheet_widget': uom.timesheet_widget, + } for uom in [timesheet_encode_uom, project_time_mode_uom] + } + return session_info + def _task_get_page_view_values(self, task, access_token, **kwargs): values = super(ProjectCustomerPortal, self)._task_get_page_view_values(task, access_token, **kwargs) domain = request.env['account.analytic.line']._timesheet_get_portal_domain() diff --git a/addons/project/controllers/portal.py b/addons/project/controllers/portal.py index e0f1cc09b6c..7ff3097d604 100644 --- a/addons/project/controllers/portal.py +++ b/addons/project/controllers/portal.py @@ -159,12 +159,7 @@ class ProjectCustomerPortal(CustomerPortal): values['task_url'] = 'project/%s/task' % project_id return request.render("project.portal_my_project", values) - @http.route("/my/project//project_sharing", type="http", auth="user", methods=['GET']) - def render_project_backend_view(self, project_id): - 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(): - return request.not_found() - + def _prepare_project_sharing_session_info(self, project): session_info = request.env['ir.http'].session_info() user_context = request.session.get_context() if request.session.uid else {} mods = conf.server_wide_modules or [] @@ -190,11 +185,20 @@ class ProjectCustomerPortal(CustomerPortal): }, }, }, + # FIXME: See if we prefer to give only the currency that the portal user just need to see the correct information in project sharing + currencies=request.env['ir.http'].get_currencies(), ) + return session_info + + @http.route("/my/project//project_sharing", type="http", auth="user", methods=['GET']) + def render_project_backend_view(self, project_id): + 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(): + return request.not_found() return request.render( 'project.project_sharing_embed', - {'session_info': session_info}, + {'session_info': self._prepare_project_sharing_session_info(project)}, ) @http.route('/my/project//task/', type='http', auth='public', website=True)