[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
This commit is contained in:
Xavier BOL (xbo)
2021-11-05 17:16:01 +01:00
parent f7bcc14d25
commit c2e8148368
+3 -2
View File
@@ -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')