diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index 695bf1f70cd..6801c31ddd7 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -251,7 +251,8 @@ class AccountAnalyticLine(models.Model): def _get_view(self, view_id=None, view_type='form', **options): """ Set the correct label for `unit_amount`, depending on company UoM """ arch, view = super()._get_view(view_id, view_type, **options) - arch = self._apply_timesheet_label(arch, view_type=view_type) + # Use of sudo as the portal user doesn't have access to uom + arch = self.sudo()._apply_timesheet_label(arch, view_type=view_type) arch = self._apply_time_label(arch, related_model=self._name) return arch, view diff --git a/addons/hr_timesheet/tests/__init__.py b/addons/hr_timesheet/tests/__init__.py index 0d998f7cee1..eaf5a5b7ee1 100644 --- a/addons/hr_timesheet/tests/__init__.py +++ b/addons/hr_timesheet/tests/__init__.py @@ -4,3 +4,4 @@ from . import test_timesheet from . import test_performance from . import test_project_task_quick_create +from . import test_portal_timesheet diff --git a/addons/hr_timesheet/tests/test_portal_timesheet.py b/addons/hr_timesheet/tests/test_portal_timesheet.py new file mode 100644 index 00000000000..33132f8f0ac --- /dev/null +++ b/addons/hr_timesheet/tests/test_portal_timesheet.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +from odoo import Command +from odoo.tests import tagged + +from odoo.addons.project.tests.test_project_sharing import TestProjectSharingCommon + +@tagged('post_install', '-at_install') +class TestPortalTimesheet(TestProjectSharingCommon): + + def test_ensure_fields_view_get_access(self): + """ Ensure that the method _fields_view_get is accessible without + raising an error for all portal users + """ + # A portal collaborator is added to a project to enable the rule analytic.account.analytic.line.timesheet.portal.user + self.project_portal.write({ + 'collaborator_ids': [ + Command.create({'partner_id': self.user_portal.partner_id.id}), + ], + }) + for view in ['form', 'tree']: + # Ensure that uom.uom records are not present in cache + self.env.invalidate_all() + # Should not raise any access error + self.env['account.analytic.line'].with_user(self.user_portal).get_view(view_type=view)