[FIX] base,website_google_map: fix partner address not showing
Following commit 983c7e8152.
`_compute_display_name` is overridden in partner to force `show_adress` and some
other context variables to None. When those values are in the context, calling
`display_name` can give a different result than calling `name_get()[0][1]`.
This commit reverts the changes of the mentioned commit where the behavior is
actually different, that is, when `show_address` is in the context.
It also adds a comment on the `_compute_display_name` method to avoid further
mistakes.
closes odoo/odoo#29510
This commit is contained in:
@@ -43,7 +43,7 @@ class GoogleMap(http.Controller):
|
||||
partner_data["partners"].append({
|
||||
'id': partner.id,
|
||||
'name': escape(partner.name),
|
||||
'address': escape('\n'.join(partner.display_name.split('\n')[1:])),
|
||||
'address': escape('\n'.join(partner.name_get()[0][1].split('\n')[1:])),
|
||||
'latitude': escape(str(partner.partner_latitude)),
|
||||
'longitude': escape(str(partner.partner_longitude)),
|
||||
})
|
||||
|
||||
@@ -643,7 +643,7 @@ class Contact(models.AbstractModel):
|
||||
opf = options and options.get('fields') or ["name", "address", "phone", "mobile", "email"]
|
||||
opsep = options and options.get('separator') or "\n"
|
||||
value = value.sudo().with_context(show_address=True)
|
||||
name_get = value.display_name
|
||||
name_get = value.name_get()[0][1]
|
||||
|
||||
val = {
|
||||
'name': name_get.split("\n")[0],
|
||||
|
||||
@@ -1560,6 +1560,17 @@ class BaseModel(MetaModel('DummyModel', (object,), {'_register': False})):
|
||||
|
||||
@api.depends(lambda self: (self._rec_name,) if self._rec_name else ())
|
||||
def _compute_display_name(self):
|
||||
"""Compute the value of the `display_name` field.
|
||||
|
||||
In general `display_name` is equal to calling `name_get()[0][1]`.
|
||||
|
||||
In that case, it is recommended to use `display_name` to uniformize the
|
||||
code and to potentially take advantage of prefetch when applicable.
|
||||
|
||||
However some models might override this method. For them, the behavior
|
||||
might differ, and it is important to select which of `display_name` or
|
||||
`name_get()[0][1]` to call depending on the desired result.
|
||||
"""
|
||||
names = dict(self.name_get())
|
||||
for record in self:
|
||||
record.display_name = names.get(record.id, False)
|
||||
|
||||
Reference in New Issue
Block a user