[FIX] web: prevent selecting an invalid scale in calendar
By pressing the date in the calendar's date picker, a function computes a new scale to be used depending on the previous focused date and scale, for example clicking on the focused date in month scale will switch to week and so on. However it bypasses the scales that are available on the calendar's definition. It is now prevented. X-original-commit: a9059b0bee02f635d563b45ee94f04bab5532fe4 Part-of: odoo/odoo#101603
This commit is contained in:
@@ -45,6 +45,10 @@ export class CalendarModel extends Model {
|
||||
? deserializeDateTime(params.context.initial_date)
|
||||
: luxon.DateTime.local();
|
||||
}
|
||||
// Prevent picking a scale that is not supported by the view
|
||||
if (!this.meta.scales.includes(this.meta.scale)) {
|
||||
this.meta.scale = this.meta.scales[0];
|
||||
}
|
||||
const data = { ...this.data };
|
||||
await this.keepLast.add(this.updateData(data));
|
||||
this.data = data;
|
||||
|
||||
@@ -3934,4 +3934,21 @@ QUnit.module("Views", ({ beforeEach }) => {
|
||||
// test would fail here if we don't ignore readonly modifier
|
||||
assert.containsOnce(target, ".o_cw_popover");
|
||||
});
|
||||
|
||||
QUnit.test("can not select invalid scale from datepicker", async (assert) => {
|
||||
await makeView({
|
||||
type: "calendar",
|
||||
resModel: "event",
|
||||
serverData,
|
||||
arch: `
|
||||
<calendar date_start="start" date_stop="stop" all_day="allday" mode="month" scales="month,year">
|
||||
<field name="name" attrs="{'readonly': [['unknown_field', '=', 42]]}" />
|
||||
</calendar>
|
||||
`,
|
||||
});
|
||||
|
||||
await click(target, ".ui-datepicker-today");
|
||||
// test would fail here if we went to week mode
|
||||
assert.containsOnce(target, ".fc-dayGridMonth-view");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user