From ce275878bd8b10f399017eaac36fd782461a48c2 Mon Sep 17 00:00:00 2001 From: "Laurent Stukkens (LTU)" Date: Thu, 27 May 2021 15:05:12 +0000 Subject: [PATCH] [IMP] web: add the special write commands to the orm service file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit brings the x2ManyCommands from the legacy basic_model.js file into the orm_service.js file in order to ease devs works as it has been done in the Commands class in Python code. closes odoo-dev/odoo#891 Signed-off-by: Géry Debongnie (ged) --- addons/web/static/src/core/orm_service.js | 44 +++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/addons/web/static/src/core/orm_service.js b/addons/web/static/src/core/orm_service.js index dccf57efefa..b765fdc4627 100644 --- a/addons/web/static/src/core/orm_service.js +++ b/addons/web/static/src/core/orm_service.js @@ -22,6 +22,50 @@ function assignOptions(kwargs, options, whileList) { // ORM // ----------------------------------------------------------------------------- +/** + * One2many and Many2many fields expect a special command to manipulate the + * relation they implement. + * + * Internally, each command is a 3-elements tuple where the first element is a + * mandatory integer that identifies the command, the second element is either + * the related record id to apply the command on (commands update, delete, + * unlink and link) either 0 (commands create, clear and set), the third + * element is either the ``values`` to write on the record (commands create + * and update) either the new ``ids`` list of related records (command set), + * either 0 (commands delete, unlink, link, and clear). + */ +export const Commands = { + create(virtualID, values) { + delete values.id; + return [0, virtualID || false, values]; + }, + + update(id, values) { + delete values.id; + return [1, id, values]; + }, + + delete(id) { + return [2, id, false]; + }, + + forget(id) { + return [3, id, false]; + }, + + linkTo(id) { + return [4, id, false]; + }, + + deleteAll() { + return [5, false, false]; + }, + + replaceWith(ids) { + return [6, false, ids]; + }, +}; + class ORM { constructor(rpc, user) { this.rpc = rpc;