summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@odoo.com>2017-03-07 16:29:09 +0100
committerAaron Bohy <aab@odoo.com>2017-04-11 19:44:38 +0200
commit7a1d7cb2414f708a1d9f167412747bf98e2654e7 (patch)
tree0e3ef361561fe62ad24a83be361da3e702001dad /addons/web/static/src/js/views/basic/basic_model.js
parent86a87aa8b0dde2237cfe1bb769724e8ed269b62e (diff)
[FIX] web: allow edition of one2many with widget many2many
It is quite rare, but it happens that a one2many field has to be edited with a many2many widget: it allows the fact that records are directly created, and only later linked to the main record. But the BasicModel only used the field type to determine which commands it had to send. In this commit, we introduce a magic flag _forceM2MLink, which, if set to true, tells the BasicModel to treat the field as a many2many.
Diffstat (limited to 'addons/web/static/src/js/views/basic/basic_model.js')
-rw-r--r--addons/web/static/src/js/views/basic/basic_model.js5
1 files changed, 4 insertions, 1 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 04c80764e00..8afd87aedfe 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -361,6 +361,7 @@ var BasicModel = AbstractModel.extend({
delete element._cache;
delete element._changes;
+ delete element._forceM2MLink;
delete element.static;
delete element.parentID;
delete element.relation_field;
@@ -1141,6 +1142,8 @@ var BasicModel = AbstractModel.extend({
list._changes.push(newRecord.id);
break;
case 'ADD_M2M':
+ // force to use link command instead of create command
+ list._forceM2MLink = true;
// handle multiple add: command[2] may be a dict of values (1
// record added) or an array of dict of values
var data = _.isArray(command.ids) ? command.ids : [command.ids];
@@ -1576,7 +1579,7 @@ var BasicModel = AbstractModel.extend({
relIds = _.pluck(relData, 'res_id');
commands[fieldName] = [];
- if (type === 'many2many') {
+ if (type === 'many2many' || list._forceM2MLink) {
// deliberately generate a single 'replace' command instead
// of a 'delete' and a 'link' commands with the exact diff
// because 1) performance-wise it doesn't change anything