[FIX] web: calendar filter without main color attr

# Before
A calendar arch without a main color attr that has
some dynamic filters would crash.

# After
No traceback occurs, the default color is used.

closes odoo/odoo#103350

X-original-commit: 54e690b9c789ea862ce3039dd6040e210fa80b39
Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
Signed-off-by: Bruno Boi (boi) <boi@odoo.com>
This commit is contained in:
Bruno Boi
2022-10-18 12:19:37 +02:00
parent 93d63a7f28
commit e0139fc677
2 changed files with 26 additions and 2 deletions
@@ -715,8 +715,9 @@ export class CalendarModel extends Model {
const colorField = fields[fieldMapping.color];
const hasFilterColorAttr = !!colorFieldName;
const sameRelatedModel =
colorField.relation === field.relation ||
(colorField.related && colorField.related.startsWith(`${fieldName}.`));
colorField &&
(colorField.relation === field.relation ||
(colorField.related && colorField.related.startsWith(`${fieldName}.`)));
let colorIndex = null;
if (hasFilterColorAttr || sameRelatedModel) {
colorIndex = rawFilter.colorIndex;
@@ -2349,6 +2349,29 @@ QUnit.module("Views", ({ beforeEach }) => {
);
});
QUnit.test(`Colors: dynamic filters without any color attr`, async (assert) => {
await makeView({
type: "calendar",
resModel: "event",
serverData,
arch: `
<calendar date_start="start" date_stop="stop">
<field name="user_id" filters="1" invisible="1"/>
</calendar>
`,
});
assert.hasClass(findEvent(target, 1), "o_calendar_color_0");
assert.hasClass(findEvent(target, 2), "o_calendar_color_0");
assert.hasClass(findEvent(target, 3), "o_calendar_color_0");
assert.hasClass(findEvent(target, 4), "o_calendar_color_0");
assert.hasClass(findEvent(target, 5), "o_calendar_color_0");
assert.containsOnce(target, ".o_calendar_filter[data-name=user_id]");
assert.containsNone(
findFilterPanelSection(target, "user_id"),
"[class*='o_cw_filter_color_']"
);
});
QUnit.test(`Colors: dynamic filters without color attr (related)`, async (assert) => {
serverData.models.event.records = [
{