[FIX] web: kanban: conditions on relational fields

This commit aims to correctly fill in the raw_value of each
field in the qweb_context use to render the kanban templates.
For relational fields, the absence of value should be false,
instead of an empty array. Moreover, the Many2One case is
different from the x2Many cases as in the first case the
datapoint is a record, and it the last ones it is a list.
This commit is contained in:
Aaron Bohy
2017-04-11 19:44:38 +02:00
parent a1f4fe8616
commit e07f27d45e
2 changed files with 36 additions and 3 deletions
@@ -179,8 +179,10 @@ var KanbanRecord = Widget.extend({
if ((r.type === 'date' || r.type === 'datetime') && value) {
r.raw_value = value.toDate();
} else if (r.type === 'one2many' || r.type === 'many2one' || r.type === 'many2many') {
r.raw_value = value ? value.res_ids : [];
} else if (r.type === 'one2many' || r.type === 'many2many') {
r.raw_value = value.count ? value.res_ids : false;
} else if (r.type === 'many2one' ) {
r.raw_value = value.res_id || false;
} else {
r.raw_value = value;
}
+32 -1
View File
@@ -849,7 +849,38 @@ QUnit.module('Views', {
kanban.destroy();
});
});
QUnit.test('evaluate conditions on relational fields', function (assert) {
assert.expect(3);
this.data.partner.records[0].product_id = false;
this.data.partner.records[0].category_ids = [6];
var kanban = createView({
View: KanbanView,
model: 'partner',
data: this.data,
arch: '<kanban class="o_kanban_test">' +
'<field name="product_id"/>' +
'<field name="category_ids"/>' +
'<templates><t t-name="kanban-box">' +
'<div>' +
'<button t-if="!record.product_id.raw_value" class="btn_a">A</button>' +
'<button t-if="!record.category_ids.raw_value" class="btn_b">B</button>' +
'</div>' +
'</t></templates>' +
'</kanban>',
});
assert.strictEqual($('.o_kanban_record:not(.o_kanban_ghost)').length, 4,
"there should be 4 records");
assert.strictEqual($('.o_kanban_record:not(.o_kanban_ghost) .btn_a').length, 1,
"only 1 of them should have the 'Action' button");
assert.strictEqual($('.o_kanban_record:not(.o_kanban_ghost) .btn_b').length, 3,
"only 3 of them should have the 'Action' button");
kanban.destroy();
});
});
});