[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
This commit is contained in:
Xavier BOL (xbo)
2021-11-05 17:10:15 +01:00
parent 0b8961a963
commit 150686947b
2 changed files with 36 additions and 7 deletions
@@ -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()
+11 -7
View File
@@ -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/<int:project_id>/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/<int:project_id>/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/<int:project_id>/task/<int:task_id>', type='http', auth='public', website=True)