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 62898a338bd..e737df9cc9e 100644 --- a/addons/web/static/src/js/views/basic/basic_model.js +++ b/addons/web/static/src/js/views/basic/basic_model.js @@ -183,17 +183,14 @@ var BasicModel = AbstractModel.extend({ * parent. * * @todo we should remove the deleted records from the localData - * @todo is it really necessary to reload the data? it seems artificial, and - * the caller should be able to do that himself * @todo why can't we infer modelName? * * @param {string[]} recordIds list of local resources ids. They should all * be of type 'record', and of the same model * @param {string} modelName - * @param {string} parentID * @returns {Deferred} */ - deleteRecords: function (recordIds, modelName, parentID) { + deleteRecords: function (recordIds, modelName) { var self = this; var records = _.map(recordIds, function (id) { return self.localData[id]; }); return this._rpc({ @@ -208,9 +205,6 @@ var BasicModel = AbstractModel.extend({ record.res_id = record.res_ids[record.offset]; record.count--; }); - if (parentID) { - return self.reload(parentID); - } }); }, /** 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 778768b4982..e833c80e3b2 100644 --- a/addons/web/static/src/js/views/form/form_controller.js +++ b/addons/web/static/src/js/views/form/form_controller.js @@ -337,6 +337,19 @@ var FormController = BasicController.extend({ warnings.push(''); this.do_warn(_t("The following fields are invalid:"), warnings.join('')); }, + /** + * Hook method, called when record(s) has been deleted. + * + * @override + */ + _onDeletedRecords: function () { + var state = this.model.get(this.handle, {raw: true}); + if (!state.res_ids.length) { + this.do_action('history_back'); + } else { + this._super.apply(this, arguments); + } + }, /** * We just add the current ID to the state pushed. This allows the web * client to add it in the url, for example. diff --git a/addons/web/static/tests/views/form_tests.js b/addons/web/static/tests/views/form_tests.js index 2d71552b119..1f98c443eae 100644 --- a/addons/web/static/tests/views/form_tests.js +++ b/addons/web/static/tests/views/form_tests.js @@ -1852,6 +1852,42 @@ QUnit.module('Views', { form.destroy(); }); + QUnit.test('deleting the last record', function (assert) { + assert.expect(6); + + var form = createView({ + View: FormView, + model: 'partner', + data: this.data, + arch: '
', + viewOptions: { + ids: [1], + index: 0, + sidebar: true, + }, + res_id: 1, + mockRPC: function (route, args) { + assert.step(args.method); + return this._super.apply(this, arguments); + } + }); + + // open sidebar, click on delete and confirm + form.sidebar.$('button.o_dropdown_toggler_btn').click(); + form.sidebar.$('a:contains(Delete)').click(); + + testUtils.intercept(form, 'do_action', function (event) { + assert.strictEqual(event.data.action, 'history_back', + "should trigger an history back action"); + }); + assert.strictEqual($('.modal').length, 1, 'a confirm modal should be displayed'); + $('.modal .modal-footer button.btn-primary').click(); + assert.strictEqual($('.modal').length, 0, 'no confirm modal should be displayed'); + + assert.verifySteps(['read', 'unlink']); + form.destroy(); + }); + QUnit.test('empty required fields cannot be saved', function (assert) { assert.expect(5); diff --git a/addons/web/static/tests/views/kanban_tests.js b/addons/web/static/tests/views/kanban_tests.js index e44f49227d2..dd86ea4d81b 100644 --- a/addons/web/static/tests/views/kanban_tests.js +++ b/addons/web/static/tests/views/kanban_tests.js @@ -649,9 +649,8 @@ QUnit.module('Views', { }); QUnit.test('delete a column in grouped on m2o', function (assert) { - assert.expect(21); + assert.expect(25); - var nbRPCs = 0; var kanban = createView({ View: KanbanView, model: 'partner', @@ -664,9 +663,11 @@ QUnit.module('Views', { '', groupBy: ['product_id'], mockRPC: function (route, args) { - nbRPCs++; + if (args.method) { + assert.step(args.method); + } return this._super(route, args); - } + }, }); // check the initial rendering @@ -717,6 +718,7 @@ QUnit.module('Views', { "should not be able to archive the records"); assert.ok(!kanban.$('.o_kanban_header:first .o_kanban_config .o_column_unarchive').length, "should not be able to restore the records"); + assert.verifySteps(['read_group', 'unlink', 'read_group']); kanban.destroy(); });