From c2e81483688152b9c3fd5960e980ef0ec36ac1ed Mon Sep 17 00:00:00 2001 From: "Xavier BOL (xbo)" Date: Fri, 15 Oct 2021 11:41:23 +0200 Subject: [PATCH] [FIX] hr_timesheet: fix access error when load_views in project sharing Before this commit, when the user chooses to encode in 'Days', the timesheets, when a collaborator accesses to the project sharing feature for a shared project. This collaborator has an access error because he does not have any access to `uom.uom` of the current company. Indeed, we use this uom to change the label of `unit_amount` field for timesheets linked to this project shared. This commit fetches the name of the encoding for the current company in sudo to change the label of `unit_amount` field of timesheets during the load_views of project sharing feature. task-2633229 closes #77156 X-original-commit: 575315744a31a975208c82f72403ecebf3585f37 --- addons/hr_timesheet/models/hr_timesheet.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index 3e756dd201c..c8a888bc27e 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -163,9 +163,10 @@ class AccountAnalyticLine(models.Model): def _apply_time_label(self, view_arch, related_model): doc = etree.XML(view_arch) Model = self.env[related_model] - encoding_uom = self.env.company.timesheet_encode_uom_id + # Just fetch the name of the uom in `timesheet_encode_uom_id` of the current company + encoding_uom_name = self.env.company.timesheet_encode_uom_id.with_context(prefetch_fields=False).sudo().name for node in doc.xpath("//field[@widget='timesheet_uom'][not(@string)] | //field[@widget='timesheet_uom_no_toggle'][not(@string)]"): - name_with_uom = re.sub(_('Hours') + "|Hours", encoding_uom.name or '', Model._fields[node.get('name')]._description_string(self.env), flags=re.IGNORECASE) + name_with_uom = re.sub(_('Hours') + "|Hours", encoding_uom_name or '', Model._fields[node.get('name')]._description_string(self.env), flags=re.IGNORECASE) node.set('string', name_with_uom) return etree.tostring(doc, encoding='unicode')