Skip to content

Commit

Permalink
[FIX] web: check domain after action button in kanban
Browse files Browse the repository at this point in the history
When a user click on an action button, we need to check if the record
match with the domain to remove it from the view if this action change
the record value.
Special case: we filter by active field equal true, if the active field
is available in the data (field present in the kanban view).

opw-1832879

Co-authored-by: Nicolas Martinelli <nim@odoo.com>
  • Loading branch information
Gorash and nim-odoo committed Apr 9, 2018
1 parent d9f7490 commit 9961bbf
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
15 changes: 15 additions & 0 deletions addons/web/static/src/js/views/kanban/kanban_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ odoo.define('web.KanbanController', function (require) {
var BasicController = require('web.BasicController');
var Context = require('web.Context');
var core = require('web.core');
var Domain = require('web.Domain');
var view_dialogs = require('web.view_dialogs');

var _t = core._t;
Expand Down Expand Up @@ -228,10 +229,24 @@ var KanbanController = BasicController.extend({
resIDs: record.res_ids,
},
on_closed: function () {
var recordModel = self.model.localData[record.id];
var group = self.model.localData[recordModel.parentID];
var parent = self.model.localData[group.parentID];

self.model.reload(record.id).then(function (db_id) {
var data = self.model.get(db_id);
var kanban_record = event.target;
kanban_record.update(data);

// Check if we still need to display the record
var domain = parent ? parent.domain : group.domain;
if ('active' in data.data && _.pluck(domain, 0).indexOf('active') === -1) {
domain = [['active', '=', true]].concat(domain);
}
var visible = new Domain(domain).compute(data.evalContext);
if (!visible) {
kanban_record.destroy();
}
});
},
});
Expand Down
36 changes: 36 additions & 0 deletions addons/web/static/tests/views/kanban_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -1716,6 +1716,42 @@ QUnit.module('Views', {
kanban.destroy();
});

QUnit.test('button executes action and check domain', function (assert) {
assert.expect(2);

var data = this.data;
data.partner.fields.active = {string: "Active", type: "boolean", default: true};
for (var k in this.data.partner.records) {
data.partner.records[k].active = true;
}

var kanban = createView({
View: KanbanView,
model: "partner",
data: data,
arch:
'<kanban>' +
'<templates><div t-name="kanban-box">' +
'<field name="foo"/>' +
'<field name="active"/>' +
'<button type="object" name="a1" />' +
'<button type="object" name="toggle_active" />' +
'</div></templates>' +
'</kanban>',
});

testUtils.intercept(kanban, 'execute_action', function (event) {
data.partner.records[0].active = false;
event.data.on_closed();
});

assert.strictEqual(kanban.$('.o_kanban_record:contains(yop)').length, 1, "should display 'yop' record");
kanban.$('.o_kanban_record:contains(yop) button[data-name="toggle_active"]').click();
assert.strictEqual(kanban.$('.o_kanban_record:contains(yop)').length, 0, "should remove 'yop' record from the view");

kanban.destroy();
});

QUnit.test('rendering date and datetime', function (assert) {
assert.expect(2);

Expand Down

0 comments on commit 9961bbf

Please sign in to comment.