diff options
| author | Aaron Bohy <aab@odoo.com> | 2018-02-15 10:14:15 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2018-02-16 14:28:50 +0100 |
| commit | ff019aa52f4857b45ebad301757970d99df37aee (patch) | |
| tree | 409a4b1fbc24925c490412f87cc738a0cf2daa1e /addons/web/static/src/js/views/basic | |
| parent | cf03101447cf572417274f06f232056d6b944237 (diff) | |
[FIX] web: BasicModel: onchange on X2M: handle command 6
Before this rev., when an onchange returned a command 6 for an
x2many field, it was completely ignored by the BasicModel.
Diffstat (limited to 'addons/web/static/src/js/views/basic')
| -rw-r--r-- | addons/web/static/src/js/views/basic/basic_model.js | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/addons/web/static/src/js/views/basic/basic_model.js b/addons/web/static/src/js/views/basic/basic_model.js index ff4ed6d9147..6eef41f149d 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1452,22 +1452,15 @@ var BasicModel = AbstractModel.extend({ defs.push(self._applyOnChange(command[2], rec)); } else if (command[0] === 4) { // LINK TO - rec = self.localData[list._cache[command[1]]]; - if (rec) { - // modifications done on a record are discarded if - // the onchange uses a LINK TO - self.discardChanges(rec.id); - } - // the dataPoint id will be set when the record will be - // fetched (for now, this dataPoint may not exist yet) - list._changes.push({ - operation: 'ADD', - id: rec ? rec.id : null, - resID: command[1], - }); + linkRecord(list, command[1]); } else if (command[0] === 5) { // DELETE ALL list._changes = [{operation: 'REMOVE_ALL'}]; + } else if (command[0] === 6) { + list._changes = [{operation: 'REMOVE_ALL'}]; + _.each(command[2], function (resID) { + linkRecord(list, resID); + }); } }); var def = self._readUngroupedList(list).then(function () { @@ -1484,6 +1477,25 @@ var BasicModel = AbstractModel.extend({ } }); return $.when.apply($, defs); + + // inner function that adds a record (based on its res_id) to a list + // dataPoint (used for onchanges that return commands 4 (LINK TO) or + // commands 6 (REPLACE WITH)) + function linkRecord (list, resID) { + rec = self.localData[list._cache[resID]]; + if (rec) { + // modifications done on a record are discarded if the onchange + // uses a LINK TO or a REPLACE WITH + self.discardChanges(rec.id); + } + // the dataPoint id will be set when the record will be fetched (for + // now, this dataPoint may not exist yet) + list._changes.push({ + operation: 'ADD', + id: rec ? rec.id : null, + resID: resID, + }); + } }, /** * When an operation is applied to a x2many field, the field widgets |
