From af021f223b2ef3801fa012e82775054c48054b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Fri, 19 May 2017 14:22:28 +0200 Subject: [FIX] web: apply onchange when m2o or m2m is edited Before this commit, when editing a many2one (with an onchange) by clicking on the small form button on the right, then changing something, then saving the modal dialog, no onchange was triggered, because, technically, the value of the many2one was not changed, only the values from the record pointed by the many2one were. The same remarks applies to many2manys. To see this issue in odoo, you can open a product (technically, a product.template) from the 'Catalog' menu in sales, then edit it, then click on the small form view icon next to Internal Category. This is a many2one (categ_id) with an onchange. In the form view dialog, change something, for example costing method, then save. The res_id of the internal category was not changed, but an onchange should still be triggered. --- addons/web/static/src/js/views/basic/basic_model.js | 11 +++++++++++ 1 file changed, 11 insertions(+) (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 76dc10d0238..2895e5b2ff9 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -980,6 +980,17 @@ var BasicModel = AbstractModel.extend({ record._changes[fieldName] = false; return $.when(); } + + // here, we check that the many2one really changed. If the res_id is the + // same, we do not need to do any extra work. It can happen when the + // user edited a manyone (with the small form view button) with an + // onchange. In that case, the onchange is triggered, but the actual + // value did not change. + var relatedID = (record._changes && record._changes[fieldName]) || record.data[fieldName]; + var relatedRecord = this.localData[relatedID]; + if (relatedRecord && (data.id === this.localData[relatedID].res_id)) { + return $.when(); + } var rel_data = _.pick(data, 'id', 'display_name'); var def; if (rel_data.display_name === undefined) { -- cgit v1.2.3