[IMP] hr_timesheet: label on unit_amount
We want the UoM name (encoding timesheet) to be displayed in the label of unit_amount field. To do so, the field_view_get is extended to change the label on the field decorated with the `timesheet_uom` widget, in the view arch If a string attribute is set on the field, it is prior; so we only add label if no one is set to avoid breaking view inheritance. Task #39079
This commit is contained in:
@@ -77,6 +77,24 @@ class AccountAnalyticLine(models.Model):
|
||||
self.filtered(lambda t: t.project_id)._timesheet_postprocess(values)
|
||||
return result
|
||||
|
||||
@api.model
|
||||
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
|
||||
""" Set the correct label for `unit_amount`, depending on company UoM """
|
||||
result = super(AccountAnalyticLine, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
|
||||
result['arch'] = self._apply_timesheet_label(result['arch'])
|
||||
return result
|
||||
|
||||
@api.model
|
||||
def _apply_timesheet_label(self, view_arch):
|
||||
doc = etree.XML(view_arch)
|
||||
encoding_uom = self.env.user.company_id.timesheet_encode_uom_id
|
||||
# Here, we select only the unit_amount field having no string set to give priority to
|
||||
# custom inheretied view stored in database. Even if normally, no xpath can be done on
|
||||
# 'string' attribute.
|
||||
for node in doc.xpath("//field[@name='unit_amount'][@widget='timesheet_uom'][not(@string)]"):
|
||||
node.set('string', _('Duration (%s)') % (encoding_uom.name))
|
||||
return etree.tostring(doc, encoding='unicode')
|
||||
|
||||
# ----------------------------------------------------
|
||||
# Business Methods
|
||||
# ----------------------------------------------------
|
||||
|
||||
@@ -151,3 +151,10 @@ class Task(models.Model):
|
||||
'company_id': account_id.company_id.id,
|
||||
})
|
||||
return result
|
||||
|
||||
@api.model
|
||||
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
|
||||
""" Set the correct label for `unit_amount`, depending on company UoM """
|
||||
result = super(Task, self).fields_view_get(view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu)
|
||||
result['arch'] = self.env['account.analytic.line']._apply_timesheet_label(result['arch'])
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user