[FIX] web: fix issues when deleting records
This commit solves two issues with deletion: - deleting the last record in a form view now triggers a history_back action, which means that the view will be changed back to the main view (a list view for example), instead of staying in form view - deleting a record did reload the view twice in some cases.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
},
|
||||
/**
|
||||
|
||||
@@ -337,6 +337,19 @@ var FormController = BasicController.extend({
|
||||
warnings.push('</ul>');
|
||||
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.
|
||||
|
||||
@@ -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: '<form string="Partners"><field name="foo"></field></form>',
|
||||
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);
|
||||
|
||||
|
||||
@@ -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', {
|
||||
'</kanban>',
|
||||
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();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user