From d1d80a494b2a0a9e55a3232dbff291ea9f65da1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A9ry=20Debongnie?= Date: Thu, 6 Apr 2017 19:57:59 +0200 Subject: [PATCH] [FIX] web: make sure buttons are called with proper res_id Before this commit, clicking on buttons did not reload the current record, which is good. However, it kept the reference to the record after saving, even if that record could have been changed, which is definitely the case when starting from a new record and saving it (it will have the correct res_id, which is really important). --- .../web/static/src/js/views/form/form_controller.js | 6 +++++- addons/web/static/test/views/form_tests.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/js/views/form/form_controller.js b/addons/web/static/src/js/views/form/form_controller.js index 4a0561e2eca..7435332ecf4 100644 --- a/addons/web/static/src/js/views/form/form_controller.js +++ b/addons/web/static/src/js/views/form/form_controller.js @@ -454,7 +454,11 @@ var FormController = BasicController.extend({ } else { // save the record but don't switch to readonly mode def = this.saveRecord({stayInEdit: true, reload: false}).then(function () { - return self._callButtonAction(attrs, event.data.record); + // we need to reget the record to make sure we have changes made + // by the basic model, such as the new res_id, if the record is + // new. + var record = self.model.get(event.data.record.id); + return self._callButtonAction(attrs, record); }); } def.then(function () { diff --git a/addons/web/static/test/views/form_tests.js b/addons/web/static/test/views/form_tests.js index a1271785d38..fdd5fd84c64 100644 --- a/addons/web/static/test/views/form_tests.js +++ b/addons/web/static/test/views/form_tests.js @@ -662,7 +662,9 @@ QUnit.module('Views', { QUnit.test('buttons in form view, new record', function (assert) { // this simulates a situation similar to the settings forms. - assert.expect(5); + assert.expect(6); + + var resID; var form = createView({ View: FormView, @@ -681,12 +683,20 @@ QUnit.module('Views', { '', mockRPC: function (route, args) { assert.step(args.method); + if (args.method === 'create') { + return this._super.apply(this, arguments).then(function (result) { + resID = result; + return resID; + }); + } return this._super.apply(this, arguments); }, }); testUtils.intercept(form, 'execute_action', function (event) { assert.step('execute_action'); + assert.strictEqual(event.data.record_id, resID, + "execute action should be done on correct record id"); event.data.on_success(); }); form.$('.o_form_statusbar button.p').click();