| 1 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 2 |
|
| 3 |
from odoo.fields import Domain |
| 4 |
from odoo.http import request |
| 5 |
|
| 6 |
from odoo.addons.project.controllers.portal import CustomerPortal |
| 7 |
|
| 8 |
|
| 9 |
class ProjectCustomerPortal(CustomerPortal): |
| 10 |
|
| 11 |
def _get_project_sharing_company(self, project): |
| 12 |
company = project.company_id |
| 13 |
if not company: |
| 14 |
timesheet = request.env['account.analytic.line'].sudo().search([('project_id', '=', project.id)], limit=1) |
| 15 |
company = timesheet.company_id or request.env.user.company_id |
| 16 |
return company |
| 17 |
|
| 18 |
def _prepare_project_sharing_session_info(self, project): |
| 19 |
session_info = super()._prepare_project_sharing_session_info(project) |
| 20 |
company = request.env['res.company'].sudo().browse(session_info['user_companies']['current_company']) |
| 21 |
timesheet_encode_uom = company.timesheet_encode_uom_id |
| 22 |
project_time_mode_uom = company.project_time_mode_id |
| 23 |
|
| 24 |
session_info['user_companies']['allowed_companies'][company.id].update( |
| 25 |
timesheet_uom_id=timesheet_encode_uom.id, |
| 26 |
timesheet_uom_factor=project_time_mode_uom._compute_quantity( |
| 27 |
1.0, |
| 28 |
timesheet_encode_uom, |
| 29 |
round=False |
| 30 |
), |
| 31 |
) |
| 32 |
session_info['uom_ids'] = { |
| 33 |
uom.id: |
| 34 |
{ |
| 35 |
'id': uom.id, |
| 36 |
'name': uom.name, |
| 37 |
'rounding': uom.rounding, |
| 38 |
'timesheet_widget': uom.timesheet_widget, |
| 39 |
} for uom in [timesheet_encode_uom, project_time_mode_uom] |
| 40 |
} |
| 41 |
session_info['user_context']['allow_timesheets'] = project.allow_timesheets |
| 42 |
return session_info |
| 43 |
|
| 44 |
def _task_get_page_view_values(self, task, access_token, **kwargs): |
| 45 |
values = super()._task_get_page_view_values(task, access_token, **kwargs) |
| 46 |
domain = request.env['account.analytic.line']._timesheet_get_portal_domain() |
| 47 |
task_domain = Domain(domain) & Domain('task_id', '=', task.id) |
| 48 |
timesheets = request.env['account.analytic.line'].sudo().search(task_domain) |
| 49 |
|
| 50 |
values['allow_timesheets'] = task.allow_timesheets |
| 51 |
values['timesheets'] = timesheets |
| 52 |
values['is_uom_day'] = request.env['account.analytic.line']._is_timesheet_encode_uom_day() |
| 53 |
return values |