[FIX] web: ListView invisible column base on context

Before this commit, in a ListView, a field containing an invisible
attribute using an expression to be evaluated was never displayed.

Example:
<tree>
    <field name="foo" invisible="context.get('notInvisible')"/>
</tree>
The foo column is never displayed.

The solution is to use the column_invisible modifier to know if the
column should be displayed or not. column_invisible contains the
evaluated expression of the invisible attribute by the server.

closes odoo/odoo#97066

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
FrancoisGe
2022-07-29 15:53:34 +02:00
parent fd764968b8
commit 5419785092
3 changed files with 31 additions and 7 deletions
@@ -78,14 +78,13 @@ export class ListArchParser extends XMLParser {
}
} else if (node.tagName === "field") {
const fieldInfo = Field.parseFieldNode(node, models, modelName, "list");
const invisible = node.getAttribute("invisible");
fieldNodes[fieldInfo.name] = fieldInfo;
node.setAttribute("field_id", fieldInfo.name);
if (fieldInfo.widget === "handle") {
handleField = fieldInfo.name;
}
addFieldDependencies(activeFields, fieldInfo.FieldComponent.fieldDependencies);
if (!invisible || !archParseBoolean(invisible)) {
if (fieldInfo.modifiers.column_invisible !== true) {
const label = fieldInfo.FieldComponent.label;
columns.push({
...fieldInfo,
@@ -287,7 +287,7 @@ export class MockServer {
modifiersNames.forEach((attr) => {
const mod = node.getAttribute(attr);
if (mod) {
const v = evaluateExpr(mod, { context }) ? true : false;
const v = evaluateExpr(mod, context) ? true : false;
if (inTreeView && !inListHeader && attr === "invisible") {
modifiers.column_invisible = v;
} else if (v || !(attr in modifiers) || !Array.isArray(modifiers[attr])) {
@@ -1913,10 +1913,11 @@ export class MockServer {
}
// return false or the latest range start (related to the shortest
// granularity (i.e. day, week, ...))
return !values.length || values.includes(false) ? false :
values.reduce((max, value) => {
return value > max ? value : max;
});
return !values.length || values.includes(false)
? false
: values.reduce((max, value) => {
return value > max ? value : max;
});
}
/**
@@ -962,6 +962,30 @@ QUnit.module("Views", (hooks) => {
assert.containsN(target, "th", 2, "should have 2 th");
});
QUnit.test(
"invisible column based on the context are correctly displayed",
async function (assert) {
await makeView({
type: "list",
resModel: "foo",
serverData,
arch: `
<tree>
<field name="foo" invisible="context.get('notInvisible')"/>
<field name="bar" invisible="context.get('invisible')"/>
</tree>`,
context: {
invisible: true,
notInvisible: false,
},
});
// 1 th for checkbox, 1 for 1 visible column (foo)
assert.containsN(target, "th", 2, "should have 2 th");
assert.strictEqual(target.querySelectorAll("th")[1].dataset.name, "foo");
}
);
QUnit.test("boolean field has no title (data-tooltip)", async function (assert) {
await makeView({
type: "list",