From 3b7fb9934d795ff6971727089e6bbe0a77c06476 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Thu, 10 Aug 2017 17:24:43 +0200 Subject: [FIX] web: BasicModel: keep onchanges on unknown fields Let's assume the following situation: we have a one2many field displayed as a list in a form view. The list isn't editable, so when a subrecord is clicked, it is opened in a form view in a dialog. In this form view, there is a relational field X that is not in the list. In the main form view, there is a field with an onchange. When its value changes, the onchange returns a new value for the one2many: a command 5 (delete all), and a command 0 (create) with a dict of values containing a value for X. However, as X is unknown as long as no subrecord has been open in the dialog, the value for X can't be processed (we don't know the type of X, so we don't know how to process the value). Before this rev., when this happened, we discarded the value of X. This caused an issue for example in the Quotation form view (with website_quote installed): - create a new Quotation - set PartnerShip Contract as quotation template -> the onchange returns two 'create' commands for the order_line one2many - click on one of the two subrecords in the one2many -> error. This rev. ensures to keep changes on unknown fields. We keep them unprocessed, and once the form view is opened, we process and apply them. --- addons/web/static/src/js/views/basic/basic_view.js | 27 ++++++++++++++++------ 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_view.js') diff --git a/addons/web/static/src/js/views/basic/basic_view.js b/addons/web/static/src/js/views/basic/basic_view.js index 736416dea27..bdc250011f0 100644 --- a/addons/web/static/src/js/views/basic/basic_view.js +++ b/addons/web/static/src/js/views/basic/basic_view.js @@ -63,6 +63,7 @@ var BasicView = AbstractView.extend({ */ _loadData: function () { if (this.recordID) { + var self = this; var record = this.model.get(this.recordID); var viewType = this.viewType; var viewFields = Object.keys(record.fieldsInfo[viewType]); @@ -107,15 +108,27 @@ var BasicView = AbstractView.extend({ } } }); - if (fieldNames.length && !this.model.isNew(record.id)) { - return this.model.reload(this.recordID, { - fieldNames: fieldNames, - keepChanges: true, - viewType: viewType, + + var def; + if (fieldNames.length) { + // Some fields in the new view weren't in the previous one, so + // we might have stored changes for them (e.g. coming from + // onchange RPCs), that we haven't been able to process earlier + // (because those fields were unknow at that time). So we ask + // the model to process them. + def = this.model.applyRawChanges(record.id, viewType).then(function () { + if (!self.model.isNew(record.id)) { + return self.model.reload(record.id, { + fieldNames: fieldNames, + keepChanges: true, + viewType: viewType, + }); + } }); - } else { - return $.when(this.recordID); } + return $.when(def).then(function () { + return record.id; + }); } return this._super.apply(this, arguments); }, -- cgit v1.2.3