summaryrefslogtreecommitdiff
path: root/odoo/api.py
diff options
context:
space:
mode:
authorAdrian Torres <adt@odoo.com>2018-12-17 09:46:18 +0000
committerAdrian Torres <adt@odoo.com>2019-07-05 09:04:45 +0000
commit407f1f6cdb87a59bbad9f853078d7345cdf9f60c (patch)
treef15809ef5b5493fe1efc7c7d4e1b8bf9ed8ec5a4 /odoo/api.py
parent9e71d57d11faf3fabd00b8a09188e9d4f9808c63 (diff)
[REM] api: remove helpers one and aggregate
`api.one` has been deprecated since v9 because it often makes the code less clear and behaves in ways developers and readers may not expect since functions decorated with it usually expect a `list` of record(s) instead of the recordset, whereas most modern Odoo code expects `self` to be a recordset. The function `aggregate` was solely being used by `api.one` thus it has also been removed since there doesn't seem to be any other use for it thus far. closes odoo/odoo#34555 Signed-off-by: Raphael Collet (rco) <rco@openerp.com>
Diffstat (limited to 'odoo/api.py')
-rw-r--r--odoo/api.py51
1 files changed, 1 insertions, 50 deletions
diff --git a/odoo/api.py b/odoo/api.py
index 614101756a2..99fcdcaa6e2 100644
--- a/odoo/api.py
+++ b/odoo/api.py
@@ -34,7 +34,7 @@
__all__ = [
'Environment',
'Meta', 'guess', 'noguess',
- 'model', 'multi', 'one',
+ 'model', 'multi',
'model_cr', 'model_cr_context',
'cr', 'cr_context',
'cr_uid', 'cr_uid_context',
@@ -275,19 +275,6 @@ def downgrade(method, value, self, args, kwargs):
return value.ids
-def aggregate(method, value, self):
- """ Aggregate record-style ``value`` for a method decorated with ``@one``. """
- spec = getattr(method, '_returns', None)
- if spec:
- # value is a list of instances, concatenate them
- model, _, _ = spec
- if model == 'self':
- return sum(value, self.browse())
- elif model:
- return sum(value, self.env[model])
- return value
-
-
def split_context(method, args, kwargs):
""" Extract the context from a pair of positional and keyword arguments.
Return a triple ``context, args, kwargs``.
@@ -337,42 +324,6 @@ def multi(method):
return method
-def one(method):
- """ Decorate a record-style method where ``self`` is expected to be a
- singleton instance. The decorated method automatically loops on records,
- and makes a list with the results. In case the method is decorated with
- :func:`returns`, it concatenates the resulting instances. Such a
- method::
-
- @api.one
- def method(self, args):
- return self.name
-
- may be called in both record and traditional styles, like::
-
- # recs = model.browse(cr, uid, ids, context)
- names = recs.method(args)
-
- names = model.method(cr, uid, ids, args, context=context)
-
- .. deprecated:: 9.0
-
- :func:`~.one` often makes the code less clear and behaves in ways
- developers and readers may not expect.
-
- It is strongly recommended to use :func:`~.multi` and either
- iterate on the ``self`` recordset or ensure that the recordset
- is a single record with :meth:`~odoo.models.Model.ensure_one`.
- """
- def loop(method, self, *args, **kwargs):
- result = [method(rec, *args, **kwargs) for rec in self]
- return aggregate(method, result, self)
-
- wrapper = decorator(loop, method)
- wrapper._api = 'one'
- return wrapper
-
-
def model_cr(method):
""" Decorate a record-style method where ``self`` is a recordset, but its
contents is not relevant, only the model is. Such a method::