From 407f1f6cdb87a59bbad9f853078d7345cdf9f60c Mon Sep 17 00:00:00 2001 From: Adrian Torres <adt@odoo.com> Date: Mon, 17 Dec 2018 09:46:18 +0000 Subject: [PATCH] [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> --- odoo/api.py | 51 +-------------------------------------------------- 1 file changed, 1 insertion(+), 50 deletions(-) diff --git a/odoo/api.py b/odoo/api.py index 614101756a21..99fcdcaa6e2e 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:: -- GitLab