diff --git a/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js b/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js
index 589c3ebce31..0eb52b4874c 100644
--- a/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js
+++ b/addons/web/static/src/views/calendar/calendar_common/calendar_common_renderer.js
@@ -91,7 +91,7 @@ export class CalendarCommonRenderer extends Component {
eventResize: this.onEventResize,
eventResizeStart: this.onEventResizeStart,
events: (_, successCb) => successCb(this.mapRecordsToEvents()),
- firstDay: this.props.model.firstDayOfWeek % 7,
+ firstDay: this.props.model.firstDayOfWeek,
header: false,
height: "parent",
locale: luxon.Settings.defaultLocale,
diff --git a/addons/web/static/src/views/calendar/calendar_model.js b/addons/web/static/src/views/calendar/calendar_model.js
index 9d2054e055c..e824dcc9d81 100644
--- a/addons/web/static/src/views/calendar/calendar_model.js
+++ b/addons/web/static/src/views/calendar/calendar_model.js
@@ -29,7 +29,7 @@ export class CalendarModel extends Model {
...params,
activeFields,
fields,
- firstDayOfWeek: localization.weekStart,
+ firstDayOfWeek: (localization.weekStart || 0) % 7,
formViewId: params.formViewId || formViewIdFromConfig,
};
@@ -361,8 +361,8 @@ export class CalendarModel extends Model {
}
if (["week", "month"].includes(scale)) {
- const weekday = start.weekday < firstDayOfWeek ? firstDayOfWeek - 7 : firstDayOfWeek;
- start = start.set({ weekday });
+ const currentWeekOffset = (start.weekday - firstDayOfWeek + 7) % 7;
+ start = start.minus({ days: currentWeekOffset });
end = start.plus({ weeks: scale === "week" ? 1 : 6, days: -1 });
}
diff --git a/addons/web/static/tests/views/calendar/calendar_view_tests.js b/addons/web/static/tests/views/calendar/calendar_view_tests.js
index 97c5d929561..fd15ac4a6a3 100644
--- a/addons/web/static/tests/views/calendar/calendar_view_tests.js
+++ b/addons/web/static/tests/views/calendar/calendar_view_tests.js
@@ -43,6 +43,7 @@ import { dialogService } from "@web/core/dialog/dialog_service";
import { localization } from "@web/core/l10n/localization";
import { registry } from "@web/core/registry";
import { userService } from "@web/core/user_service";
+import { CalendarYearRenderer } from "@web/views/calendar/calendar_year/calendar_year_renderer";
import { actionService } from "@web/webclient/actions/action_service";
import { getTimePickers } from "../../core/datetime/datetime_test_helpers";
import { CalendarController } from "@web/views/calendar/calendar_controller";
@@ -2670,7 +2671,6 @@ QUnit.module("Views", ({ beforeEach }) => {
`,
});
-
const colorClass = Array.from(findEvent(target, 1).classList).find((className) =>
className.startsWith("o_calendar_color_")
);
@@ -4121,7 +4121,7 @@ QUnit.module("Views", ({ beforeEach }) => {
});
QUnit.test(`Monday week start week mode`, async (assert) => {
- assert.expect(3);
+ assert.expect(4);
patchDate(2019, 8, 15, 8, 0, 0); // 2019-09-15 08:00:00
// the week start depends on the locale
@@ -4162,10 +4162,15 @@ QUnit.module("Views", ({ beforeEach }) => {
"Sun 15",
"The last day of the week should be Sunday the 15th"
);
+ assert.strictEqual(
+ target.querySelector(".fc-head .fc-week-number").textContent,
+ "Week 37",
+ "The number of the week should be correct"
+ );
});
QUnit.test(`Saturday week start week mode`, async (assert) => {
- assert.expect(3);
+ assert.expect(4);
patchDate(2019, 8, 12, 8, 0, 0); // 2019-09-12 08:00:00
@@ -4207,6 +4212,118 @@ QUnit.module("Views", ({ beforeEach }) => {
"Fri 13",
"The last day of the week should be Friday the 13th"
);
+ assert.strictEqual(
+ target.querySelector(".fc-head .fc-week-number").textContent,
+ "Week 36",
+ "The number of the week should be correct"
+ );
+ });
+
+ QUnit.test(`Monday week start year mode`, async (assert) => {
+ assert.expect(4);
+
+ patchDate(2019, 8, 15, 8, 0, 0); // 2019-09-15 08:00:00
+ // the week start depends on the locale
+ patchWithCleanup(localization, { weekStart: 1 });
+
+ patchWithCleanup(CalendarYearRenderer.prototype, {
+ get options() {
+ return { ...super.options, weekNumbers: true };
+ },
+ });
+
+ await makeView({
+ type: "calendar",
+ resModel: "event",
+ serverData,
+ arch: `
+
+ `,
+ mockRPC(route, { method, model, kwargs }) {
+ if (model === "event" && method === "search_read") {
+ assert.deepEqual(
+ kwargs.domain,
+ [
+ ["start", "<=", "2019-12-31 22:59:59"],
+ ["stop", ">=", "2018-12-31 23:00:00"],
+ ],
+ "The domain to search events in should be correct"
+ );
+ }
+ },
+ });
+
+ const weekRow = target.querySelector(".fc-day-top.fc-today").closest("tr");
+ const weekDays = weekRow.querySelectorAll(".fc-day-top");
+ assert.strictEqual(
+ weekDays[0].textContent,
+ "9",
+ "The first day of the week should be Monday the 9th"
+ );
+ assert.strictEqual(
+ weekDays[weekDays.length - 1].textContent,
+ "15",
+ "The last day of the week should be Sunday the 15th"
+ );
+ assert.strictEqual(
+ weekRow.querySelector(".fc-week-number").textContent,
+ "37",
+ "The number of the week should be correct"
+ );
+ });
+
+ QUnit.test(`Sunday week start year mode`, async (assert) => {
+ assert.expect(4);
+
+ patchDate(2019, 8, 15, 8, 0, 0); // 2019-09-15 08:00:00
+ // the week start depends on the locale
+ // the localization presents a python-like 1 to 7 weekStart value
+ patchWithCleanup(localization, { weekStart: 7 });
+
+ patchWithCleanup(CalendarYearRenderer.prototype, {
+ get options() {
+ return { ...super.options, weekNumbers: true };
+ },
+ });
+
+ await makeView({
+ type: "calendar",
+ resModel: "event",
+ serverData,
+ arch: `
+
+ `,
+ mockRPC(route, { method, model, kwargs }) {
+ if (model === "event" && method === "search_read") {
+ assert.deepEqual(
+ kwargs.domain,
+ [
+ ["start", "<=", "2019-12-31 22:59:59"],
+ ["stop", ">=", "2018-12-31 23:00:00"],
+ ],
+ "The domain to search events in should be correct"
+ );
+ }
+ },
+ });
+
+ const weekRow = target.querySelector(".fc-day-top.fc-today").closest("tr");
+ const weekDays = weekRow.querySelectorAll(".fc-day-top");
+ assert.strictEqual(
+ weekDays[0].textContent,
+ "15",
+ "The first day of the week should be Sunday the 15th"
+ );
+ assert.strictEqual(
+ weekDays[weekDays.length - 1].textContent,
+ "21",
+ "The last day of the week should be Saturday the 21st"
+ );
+ assert.strictEqual(
+ weekRow.querySelector(".fc-week-number").textContent,
+ "38",
+ "The number of the week should be correct"
+ );
});
QUnit.test(