[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:
parent
00762bbae0
commit
be5717434e
|
@ -742,7 +742,7 @@ class Field(object):
|
||||||
return value
|
return value
|
||||||
return bool(value) and ustr(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. """
|
""" convert `value` from the cache to a suitable display name. """
|
||||||
return ustr(value)
|
return ustr(value)
|
||||||
|
|
||||||
|
@ -1221,6 +1221,10 @@ class Datetime(Field):
|
||||||
return self.from_string(value)
|
return self.from_string(value)
|
||||||
return bool(value) and ustr(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):
|
class Binary(Field):
|
||||||
type = 'binary'
|
type = 'binary'
|
||||||
|
@ -1363,7 +1367,7 @@ class Reference(Selection):
|
||||||
def convert_to_export(self, value, env):
|
def convert_to_export(self, value, env):
|
||||||
return bool(value) and value.name_get()[0][1]
|
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)
|
return ustr(value and value.display_name)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1495,7 +1499,7 @@ class Many2one(_Relational):
|
||||||
def convert_to_export(self, value, env):
|
def convert_to_export(self, value, env):
|
||||||
return bool(value) and value.name_get()[0][1]
|
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)
|
return ustr(value.display_name)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1602,7 +1606,7 @@ class _RelationalMulti(_Relational):
|
||||||
def convert_to_export(self, value, env):
|
def convert_to_export(self, value, env):
|
||||||
return bool(value) and ','.join(name for id, name in value.name_get())
|
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()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def _compute_related(self, records):
|
def _compute_related(self, records):
|
||||||
|
|
|
@ -1677,7 +1677,7 @@ class BaseModel(object):
|
||||||
if name in self._fields:
|
if name in self._fields:
|
||||||
convert = self._fields[name].convert_to_display_name
|
convert = self._fields[name].convert_to_display_name
|
||||||
for record in self:
|
for record in self:
|
||||||
result.append((record.id, convert(record[name])))
|
result.append((record.id, convert(record[name], record)))
|
||||||
else:
|
else:
|
||||||
for record in self:
|
for record in self:
|
||||||
result.append((record.id, "%s,%s" % (record._name, record.id)))
|
result.append((record.id, "%s,%s" % (record._name, record.id)))
|
||||||
|
|
Loading…
Reference in New Issue