Rationale ========= Since v8, the `display_name` field is present on all models. By default, `display_name` uses `name_get` which has pretty much the same purpose (return record name used by the web client). Gradually, many (backend) developers (and the ORM: https://github.com/odoo/odoo/commit/6da1c3ac4c036eac289597602976538e243cb939) started using `display_name` (more convenient than `record.name_get()[0][1]`) but it still had the `name_get` override. It becomes more complex than necessary and poeple start to misunderstand the two (and sometimes override both, leading to inconstiencies between `display_name`/`name_get`). To simplify the ORM and the API, we decided to keep only one of them, the `display_name` field: - It is much more convenient from a backend point of view (`record.name_get()[0][1]` vs `record.display_name`) - It is cached during the same transaction (and invalidated if its dependencies change) - It can be overridden like any other compute field (override `_compute_display_name` with any extra dependencies) - `name_get` is replaced by `read(['display_name'])` (API perceptive), which can actually be more efficient (if `display_name`'s depends are correct, the ORM will only fetch the fields it needs instead of every prefetchable field) Changes ======= - Deprecates `name_get` for the v17 and based the method on `display_name` (the opposite of before) - Converts all usage of `name_get` - Overrides of `name_get` are now overrides of `_compute_display_name` - For `res.partner`, rename the field store `display_name` into `complete_name` because `display_name` context-dependent and it makes no sense to have a compute store that is context-dependent. - Previously, it was possible to return multiple names for the same record with `name_get`, but it was tricky and most of the usage of this `name_get` didn't take this into account. The only example of this is the `name_get` of `product.product` (now use `", ".join(<names>)`). Part-of: odoo/odoo#122085
59 lines
2.5 KiB
Python
59 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
from odoo import http
|
|
from odoo.http import request
|
|
from odoo.tools.json import scriptsafe
|
|
|
|
|
|
class GoogleMap(http.Controller):
|
|
'''
|
|
This class generates on-the-fly partner maps that can be reused in every
|
|
website page. To do so, just use an ``<iframe ...>`` whose ``src``
|
|
attribute points to ``/google_map`` (this controller generates a complete
|
|
HTML5 page).
|
|
|
|
URL query parameters:
|
|
- ``partner_ids``: a comma-separated list of ids (partners to be shown)
|
|
- ``partner_url``: the base-url to display the partner
|
|
(eg: if ``partner_url`` is ``/partners/``, when the user will click on
|
|
a partner on the map, it will be redirected to <myodoo>.com/partners/<id>)
|
|
|
|
In order to resize the map, simply resize the ``iframe`` with CSS
|
|
directives ``width`` and ``height``.
|
|
'''
|
|
|
|
@http.route(['/google_map'], type='http', auth="public", website=True, sitemap=False)
|
|
def google_map(self, *arg, **post):
|
|
clean_ids = []
|
|
for partner_id in post.get('partner_ids', "").split(","):
|
|
try:
|
|
clean_ids.append(int(partner_id))
|
|
except ValueError:
|
|
pass
|
|
partners = request.env['res.partner'].sudo().search([("id", "in", clean_ids),
|
|
('website_published', '=', True), ('is_company', '=', True)])
|
|
partner_data = {
|
|
"counter": len(partners),
|
|
"partners": []
|
|
}
|
|
for partner in partners.with_context(show_address=True):
|
|
partner_data["partners"].append({
|
|
'id': partner.id,
|
|
'name': partner.name,
|
|
'address': '\n'.join(partner.display_name.split('\n')[1:]),
|
|
'latitude': str(partner.partner_latitude) if partner.partner_latitude else False,
|
|
'longitude': str(partner.partner_longitude) if partner.partner_longitude else False,
|
|
})
|
|
if 'customers' in post.get('partner_url', ''):
|
|
partner_url = '/customers/'
|
|
else:
|
|
partner_url = '/partners/'
|
|
|
|
google_maps_api_key = request.website.google_maps_api_key
|
|
values = {
|
|
'partner_url': partner_url,
|
|
'partner_data': scriptsafe.dumps(partner_data),
|
|
'google_maps_api_key': google_maps_api_key,
|
|
}
|
|
return request.render("website_google_map.google_map", values)
|