Files
odoo_source/addons/hr_timesheet/controllers/project.py
T
Xavier BOL (xbo) 70e5f6ccbb [IMP] project: get parent task of another project in project sharing
Before this commit, the portal user can see the parent stat button in
project sharing form view of task if the parent is in the same project.
This button can be clicked and it redirects the user to the parent task
form view in the project sharing.

This commit improves this button and its visibility in project sharing
feature. The button is visible only if the current user has access to
the project of the parent task. That is the privacy visibility of the
project should be set to 'portal'. If the portal user has access to the
project of the parent task and he is not a collaborator of this project,
then the current user will be redirected to the classic portal view of
the parent task. If it is a collaborator then we display the parent task
in the project sharing feature.

task-2648955

Closes #82379
2022-02-14 13:22:36 +01:00

53 lines
2.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from collections import defaultdict
from odoo.http import request
from odoo.osv import expression
from odoo.addons.project.controllers.portal import CustomerPortal
class ProjectCustomerPortal(CustomerPortal):
def _prepare_project_sharing_session_info(self, project, task=None):
session_info = super()._prepare_project_sharing_session_info(project, task)
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()
task_domain = expression.AND([domain, [('task_id', '=', task.id)]])
subtask_domain = expression.AND([domain, [('task_id', 'in', task.child_ids.ids)]])
timesheets = request.env['account.analytic.line'].sudo().search(task_domain)
subtasks_timesheets = request.env['account.analytic.line'].sudo().search(subtask_domain)
timesheets_by_subtask = defaultdict(lambda: request.env['account.analytic.line'].sudo())
for timesheet in subtasks_timesheets:
timesheets_by_subtask[timesheet.task_id] |= timesheet
values['allow_timesheets'] = task.allow_timesheets
values['timesheets'] = timesheets
values['timesheets_by_subtask'] = timesheets_by_subtask
values['is_uom_day'] = request.env['account.analytic.line']._is_timesheet_encode_uom_day()
return values