[FIX] fields: apply user timezone in display name for models using a datetime as name

For models using a datetime field as name (hr.attendance for instance), the user timezone wasn't applied in the display name.
Therefore, in the breadcrumb, the datetime was different than in the form if the user had another timezone than UTC.

This rev. is related to 27d8cb843b, but is for the 8.0 api

We are aware we introduce a tiny change of API (method signature change), which we normally prohibit, but considering the really low level of the method, the fact it is probably not ovveriden by any other modules and the fact there is no cleaner way to correct this, we are making an exception.
This commit is contained in:
Denis Ledoux 2015-01-05 15:42:59 +01:00
parent 00762bbae0
commit be5717434e
2 changed files with 9 additions and 5 deletions

View File

@ -742,7 +742,7 @@ class Field(object):
return value
return bool(value) and ustr(value)
def convert_to_display_name(self, value):
def convert_to_display_name(self, value, record=None):
""" convert `value` from the cache to a suitable display name. """
return ustr(value)
@ -1221,6 +1221,10 @@ class Datetime(Field):
return self.from_string(value)
return bool(value) and ustr(value)
def convert_to_display_name(self, value, record=None):
assert record, 'Record expected'
return Datetime.to_string(Datetime.context_timestamp(record, Datetime.from_string(value)))
class Binary(Field):
type = 'binary'
@ -1363,7 +1367,7 @@ class Reference(Selection):
def convert_to_export(self, value, env):
return bool(value) and value.name_get()[0][1]
def convert_to_display_name(self, value):
def convert_to_display_name(self, value, record=None):
return ustr(value and value.display_name)
@ -1495,7 +1499,7 @@ class Many2one(_Relational):
def convert_to_export(self, value, env):
return bool(value) and value.name_get()[0][1]
def convert_to_display_name(self, value):
def convert_to_display_name(self, value, record=None):
return ustr(value.display_name)
@ -1602,7 +1606,7 @@ class _RelationalMulti(_Relational):
def convert_to_export(self, value, env):
return bool(value) and ','.join(name for id, name in value.name_get())
def convert_to_display_name(self, value):
def convert_to_display_name(self, value, record=None):
raise NotImplementedError()
def _compute_related(self, records):

View File

@ -1677,7 +1677,7 @@ class BaseModel(object):
if name in self._fields:
convert = self._fields[name].convert_to_display_name
for record in self:
result.append((record.id, convert(record[name])))
result.append((record.id, convert(record[name], record)))
else:
for record in self:
result.append((record.id, "%s,%s" % (record._name, record.id)))