From 5511ffe03b658f5896ab96b472ed3fb1542dd05b Mon Sep 17 00:00:00 2001 From: Adrien Schoffeniels Date: Wed, 17 May 2023 09:49:18 +0000 Subject: [PATCH 1/2] [IMP] web: add onWillStart in calendar's model This commit allows to define a `onWillStartModel` method in the calendar controller that will be used as `onWillStart` option of the calendar model. Purpose: -------- The related enterprise PR introduces a new "item calendar" feature in Knowledge that allows to embed calendar views using article properties to display these articles in the calendar. To do so, one needs to modify the fields mapping before the model is loaded for the first time, so that the records are fetched using the properties in the search domain. The `onWillStart` option of the `useModel` function is perfectly suited for this. Task-3239985 Part-of: odoo/odoo#121608 --- .../src/views/calendar/calendar_controller.js | 5 +++ .../views/calendar/calendar_view_tests.js | 36 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/addons/web/static/src/views/calendar/calendar_controller.js b/addons/web/static/src/views/calendar/calendar_controller.js index 9f070d14d66..42f9e6ec4f9 100644 --- a/addons/web/static/src/views/calendar/calendar_controller.js +++ b/addons/web/static/src/views/calendar/calendar_controller.js @@ -48,6 +48,8 @@ export class CalendarController extends Component { resModel: this.props.resModel, domain: this.props.domain, fields: this.props.fields, + }, { + onWillStart: this.onWillStartModel.bind(this), }); this.displayName = this.env.config.getDisplayName(); @@ -214,6 +216,9 @@ export class CalendarController extends Component { }, }); } + + onWillStartModel() {} + async setDate(move) { let date = null; switch (move) { 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 067505d5c87..a8a8c82a622 100644 --- a/addons/web/static/tests/views/calendar/calendar_view_tests.js +++ b/addons/web/static/tests/views/calendar/calendar_view_tests.js @@ -46,10 +46,14 @@ import { userService } from "@web/core/user_service"; import { CharField } from "@web/views/fields/char/char_field"; import { actionService } from "@web/webclient/actions/action_service"; import { getTimePickers } from "../../core/datetime/datetime_test_helpers"; +import { CalendarController } from "@web/views/calendar/calendar_controller"; +import { calendarView } from "@web/views/calendar/calendar_view"; +import { onWillRender } from "@odoo/owl"; const fieldRegistry = registry.category("fields"); const preloadedDataRegistry = registry.category("preloadedData"); const serviceRegistry = registry.category("services"); +const viewRegistry = registry.category("views"); let target; let serverData; @@ -4766,4 +4770,36 @@ QUnit.module("Views", ({ beforeEach }) => { datepicker.remove(); } }); + + QUnit.test("check onWillStartModel is exectuted", async (assert) => { + assert.expect(3); + class TestCalendarController extends CalendarController { + setup() { + super.setup(); + onWillRender(() => { + assert.step("render"); + }); + } + onWillStartModel() { + assert.step("onWillStartModel"); + } + } + + viewRegistry.add("test_calendar_view", { + ...calendarView, + Controller: TestCalendarController, + }); + + await makeView({ + type: "calendar", + resModel: "event", + serverData, + arch: ` + + `, + limit: 3, + }); + + assert.verifySteps(["onWillStartModel", "render"]); + }); }); From a084c5f1565ce9c06ea4e9663443d583db3378f7 Mon Sep 17 00:00:00 2001 From: Adrien Schoffeniels Date: Thu, 6 Jul 2023 13:55:10 +0000 Subject: [PATCH 2/2] [IMP] web: rename properties 'view in kanban' label Purpose: -------- Rename the label "view in kanban" to "display in cards" in the properties definition popover. The rationale is that the related enterprise PR allows to display the `article_properties` in the popover of the `item calendar`, using the kanban properties widget. Therefore, checking the now called "display in cards" checkbox now allows to show the property in the kanban cards and in the calendar popovers. Task-3239985 Part-of: odoo/odoo#121608 --- .../src/views/fields/properties/property_definition.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/views/fields/properties/property_definition.xml b/addons/web/static/src/views/fields/properties/property_definition.xml index 6e76222e914..4bf4315c7d3 100644 --- a/addons/web/static/src/views/fields/properties/property_definition.xml +++ b/addons/web/static/src/views/fields/properties/property_definition.xml @@ -157,7 +157,10 @@ />
- +