From 32fcc1b883008ea16e5f5b83a6c10fd18d09e576 Mon Sep 17 00:00:00 2001 From: Adrian Torres Date: Mon, 23 Sep 2019 13:03:54 +0000 Subject: [PATCH] [REM] base: deprecate resolve_2many_commands With the introduction of `new`, the use of `resolve_2many_commands` is redundant, as it accomplishes the same function with the added benefit of returning a record-like object whose API is more familiar than `resolve_2many_commands` API. closes odoo/odoo#37290 Related: odoo/enterprise#9409 Signed-off-by: Raphael Collet (rco) --- odoo/models.py | 53 -------------------------------------------------- 1 file changed, 53 deletions(-) diff --git a/odoo/models.py b/odoo/models.py index 38ce123c2be..89b7b7a099c 100644 --- a/odoo/models.py +++ b/odoo/models.py @@ -4798,59 +4798,6 @@ Record ids: %(records)s return True - @api.model - def resolve_2many_commands(self, field_name, commands, fields=None): - """ Serializes one2many and many2many commands into record dictionaries - (as if all the records came from the database via a read()). This - method is aimed at onchange methods on one2many and many2many fields. - - Because commands might be creation commands, not all record dicts - will contain an ``id`` field. Commands matching an existing record - will have an ``id``. - - :param field_name: name of the one2many or many2many field matching the commands - :type field_name: str - :param commands: one2many or many2many commands to execute on ``field_name`` - :type commands: list((int|False, int|False, dict|False)) - :param fields: list of fields to read from the database, when applicable - :type fields: list(str) - :returns: records in a shape similar to that returned by ``read()`` - (except records may be missing the ``id`` field if they don't exist in db) - :rtype: list(dict) - """ - result = [] # result (list of dict) - record_ids = [] # ids of records to read - updates = defaultdict(dict) # {id: vals} of updates on records - - for command in commands or []: - if not isinstance(command, (list, tuple)): - record_ids.append(command) - elif command[0] == 0: - result.append(command[2]) - elif command[0] == 1: - record_ids.append(command[1]) - updates[command[1]].update(command[2]) - elif command[0] in (2, 3): - record_ids = [id for id in record_ids if id != command[1]] - elif command[0] == 4: - record_ids.append(command[1]) - elif command[0] == 5: - result, record_ids = [], [] - elif command[0] == 6: - result, record_ids = [], list(command[2]) - - # read the records and apply the updates - field = self._fields[field_name] - records = self.env[field.comodel_name].browse(record_ids) - for data in records.read(fields): - data.update(updates.get(data['id'], {})) - result.append(data) - - return result - - # for backward compatibility - resolve_o2m_commands_to_record_dicts = resolve_2many_commands - @api.model def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None): """Perform a :meth:`search` followed by a :meth:`read`.