From ba7675210f1cc71cfe47a062388c39fce8c9cec0 Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Thu, 27 Jun 2019 12:17:59 +0000 Subject: [FIX] web: two o2m fields with onchanges Scenario: We have the following models: class A: submodel_1_ids = fields.One2Many(B) submodel_2_ids = fields.One2Many(B) class B: parent_model = fields.many2one(A) name = fields.Char() and the following onchange on class A: api.onchange(submodel_1_ids) def onchange_submodel1(self): // add newline to second o2m submodel_2_ids = submodel_1_ids api.onchange(submodel_2_ids) def onchange_submodel2(self): do_smth In a form view containing both o2m fields (editable="bottom" lists): 1) add a line on first o2m -> the onchange adds the same line on the other o2m 2) add a line on the second o2m Before this rev., the line (added in (2)) wasn't added at the bottom of the list, and the row in edition wasn't the newly created one. The issue occurred because we couldn't retrieve the datapoint corresponding to the other line (the one created by the onchange on the first o2m), and we thus created another which was put at the end of the list. Then, the BasicModel messed up the sort of the records because it couldn't match the virtual id of that new record with the ones in orderedResIds. We fixed the issue by preventing the model from creating a new datapoint after the onchange, by using 'ref' instead of 'res_id' to retrieve the one that already exist. closes odoo/odoo#34493 Signed-off-by: VincentSchippefilt Co-authored-by: Aaron Bohy Co-authored-by: David Monjoie --- addons/web/static/src/js/views/basic/basic_model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/web/static/src/js/views/basic/basic_model.js') 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 0cddc887f18..60c2f6a3314 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -1597,7 +1597,7 @@ var BasicModel = AbstractModel.extend({ // updating an existing (virtual) record var previousChange = _.find(oldChanges, function (operation) { var child = self.localData[operation.id]; - return child && (child.res_id === command[1]); + return child && (child.ref === command[1]); }); recID = previousChange && previousChange.id; rec = self.localData[recID]; -- cgit v1.2.3