[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 closes odoo/odoo#121608 Related: odoo/enterprise#40993 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -157,7 +157,10 @@
|
||||
/>
|
||||
</div>
|
||||
<div t-if="!props.hideKanbanOption" class="o_field_property_definition_kanban d-contents mb-3 mb-sm-0">
|
||||
<label t-att-for="getUniqueDomID('kanban')" class="o_form_label align-self-center text-900">View In Kanban</label>
|
||||
<label t-att-for="getUniqueDomID('kanban')" class="o_form_label align-self-center text-900">
|
||||
Display in Cards
|
||||
<sup class="text-info" title="Whether or not this Property Field is displayed in the Calendar, Cards & Kanban views">?</sup>
|
||||
</label>
|
||||
<CheckBox
|
||||
id="getUniqueDomID('kanban')"
|
||||
value="props.propertyDefinition.view_in_kanban"
|
||||
|
||||
@@ -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: `
|
||||
<calendar js_class="test_calendar_view" date_start="start" date_stop="stop" all_day="allday" mode="month"/>
|
||||
`,
|
||||
limit: 3,
|
||||
});
|
||||
|
||||
assert.verifySteps(["onWillStartModel", "render"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user