Files
odoo_source/addons/test_xlsx_export/models.py
T
Rémy Voet (ryv) 3c62ca1eb9 [REM] core: remove name_get API
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
2023-06-28 17:41:19 +02:00

38 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class NewModel(models.Model):
_name = 'export.integer'
_description = 'Export: Integer'
value = fields.Integer(default=4)
def _compute_display_name(self):
for record in self:
record.display_name = f"{self._name}:{record.value}"
class GroupOperator(models.Model):
_name = 'export.group_operator'
_description = 'Export Group Operator'
int_sum = fields.Integer(group_operator='sum')
int_max = fields.Integer(group_operator='max')
float_min = fields.Float(group_operator='min')
float_avg = fields.Float(group_operator='avg')
float_monetary = fields.Monetary(currency_field='currency_id', group_operator='sum')
currency_id = fields.Many2one('res.currency')
date_max = fields.Date(group_operator='max')
bool_and = fields.Boolean(group_operator='bool_and')
bool_or = fields.Boolean(group_operator='bool_or')
many2one = fields.Many2one('export.integer')
one2many = fields.One2many('export.group_operator.one2many', 'parent_id')
class GroupOperatorO2M(models.Model):
_name = 'export.group_operator.one2many'
_description = 'Export Group Operator One2Many'
parent_id = fields.Many2one('export.group_operator')
value = fields.Integer()