summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/basic/basic_model.js
diff options
context:
space:
mode:
authorMartin Geubelle <mge@odoo.com>2017-09-13 14:45:55 +0200
committerGéry Debongnie <ged@odoo.com>2017-09-20 10:05:13 +0200
commit3136fc1643996f319faf500e303f586d18908010 (patch)
treeff79f907f3b04a47ec6d73969f6c5fe995751ac5 /addons/web/static/src/js/views/basic/basic_model.js
parent3069734d4f13ff5b09331def54d85a4f2d607178 (diff)
[FIX] web: reuse datapoint with onchange one one2many
Since the rev. https://github.com/odoo/odoo/commit/2728fe1ec1ac7e99819d0f30f29a1814b00c82a4 the onchange create command (0) send the virtual id as second argument. This argument is sent back from the server and can then be used by the client. As the client knows the virtual id, it can easily reuse the datapoint created for this record and thus avoid creating a new one. Creating a new datapoint can potentially lead to problems if the record has for example specialData, that won't be kept.
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.js18
1 files changed, 15 insertions, 3 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 5b6eb35b4ac..965237e1df1 100644
--- a/addons/web/static/src/js/views/basic/basic_model.js
+++ b/addons/web/static/src/js/views/basic/basic_model.js
@@ -1307,13 +1307,25 @@ var BasicModel = AbstractModel.extend({
record._changes[name] = list.id;
var shouldLoad = false;
list._changes = list._changes || [];
+
+ // save it in case of a [5] which will remove the _changes
+ var oldChanges = list._changes;
_.each(val, function (command) {
- var rec;
+ var rec, recID;
if (command[0] === 0 || command[0] === 1) {
// CREATE or UPDATE
+ if (command[0] === 0 && command[1]) {
+ // updating an existing (virtual) record
+ var previousChange = _.find(oldChanges, function (operation) {
+ var child = self.localData[operation.id];
+ return child && (child.res_id === command[1]);
+ });
+ recID = previousChange && previousChange.id;
+ rec = self.localData[recID];
+ }
if (command[0] === 1 && command[1]) {
// updating an existing record
- var recID = _.find(list.data, function (childID) {
+ recID = _.find(list.data, function (childID) {
var child = self.localData[childID];
return child.res_id === command[1];
});
@@ -1327,7 +1339,7 @@ var BasicModel = AbstractModel.extend({
modelName: list.model,
parentID: list.id,
viewType: list.viewType,
- ref: command[1],
+ ref: command[1],
};
if (command[0] === 1) {
params.res_id = command[1];