[FIX] web: check domain after action button in kanban
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>
This commit is contained in:
committed by
Nicolas Martinelli
co-authored by
Nicolas Martinelli
parent
d9f7490f55
commit
9961bbf4eb
@@ -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;
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user