From 99ae418bf24171fbc6bb27584059c27efb857e77 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 7 Jun 2017 12:56:21 +0200 Subject: [FIX] web: Many2one: wait for name_create before saving The problem occurred in form views with a many2one field, when the user reproduced the following steps: - type some text in the many2one - click on 'Create ...' in the many2one dropdown to quick create (name_create RPC) the record - before the name_create returns, click on 'Save'. When this happened, the record was saved before the many2one was updated with its new value. So the record was incorrectly saved, and the view was again dirty as soon as the name_create returned, even if it was in 'readonly'. So after saving, a 'Changes will be discarded' dialog opened when the user tried to leave the form. We fix this issue by making the controller wait for the name_create to return, and for the many2one to update its value, before saving. This issue could also occur in list views. --- addons/web/static/src/js/views/basic/basic_controller.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'addons/web/static/src/js/views/basic/basic_controller.js') diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index 53e5be8ff6e..4f6cf5e2ebb 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -186,8 +186,12 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { // user if some discarding has to be made). This operation must also be // mutex-protected as commitChanges function of x2m has to be aware of // all final changes made to a row. - this.mutex.exec(this.renderer.commitChanges.bind(this.renderer, recordID || this.handle)); // TODO write a test for this - return this.mutex.exec(this._saveRecord.bind(this, recordID, options)); + var self = this; + return this.mutex + .exec(this.renderer.commitChanges.bind(this.renderer, recordID || this.handle)) + .then(function () { + return self.mutex.exec(self._saveRecord.bind(self, recordID, options)); + }); }, /** * @override -- cgit v1.2.3 From 8648d16e458f96c0e313c27e5c2bc28a468c5f17 Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 7 Jun 2017 14:54:00 +0200 Subject: [FIX] web: correctly display nocontent helper if create='0' When the root node of the arch has attribute 'create' set to '0', the generated DOM element must have classname 'o_cannot_create'. This is used to correctly display the nocontent helper (when there is no record). Before this rev., the helper indicated that the user can click on 'Create' to create a new record, even if the create action was disabled. This was for example the case in Point of Sale > Orders. --- addons/web/static/src/js/views/basic/basic_controller.js | 3 +++ 1 file changed, 3 insertions(+) (limited to 'addons/web/static/src/js/views/basic/basic_controller.js') diff --git a/addons/web/static/src/js/views/basic/basic_controller.js b/addons/web/static/src/js/views/basic/basic_controller.js index 4f6cf5e2ebb..16a066db495 100644 --- a/addons/web/static/src/js/views/basic/basic_controller.js +++ b/addons/web/static/src/js/views/basic/basic_controller.js @@ -46,6 +46,9 @@ var BasicController = AbstractController.extend(FieldManagerMixin, { * @returns {Deferred} */ start: function () { + // add classname to reflect the (absence of) access rights (used to + // correctly display the nocontent helper) + this.$el.toggleClass('o_cannot_create', !this.activeActions.create); return this._super.apply(this, arguments) .then(this._updateEnv.bind(this)); }, -- cgit v1.2.3