diff --git a/mis_builder/__manifest__.py b/mis_builder/__manifest__.py index d727bca72..caf68fedc 100644 --- a/mis_builder/__manifest__.py +++ b/mis_builder/__manifest__.py @@ -33,12 +33,13 @@ "mis_builder/static/src/components/mis_report_widget.esm.js", "mis_builder/static/src/components/mis_report_widget.xml", "mis_builder/static/src/components/mis_report_widget.css", + "mis_builder/static/src/views/form/mis_report_form_controller.esm.js", + "mis_builder/static/src/views/form/mis_report_form_view.esm.js", ], "web.report_assets_common": [ "/mis_builder/static/src/css/report.css", ], }, - "qweb": ["static/src/xml/mis_report_widget.xml"], "installable": True, "application": True, "license": "AGPL-3", diff --git a/mis_builder/static/src/components/mis_report_widget.esm.js b/mis_builder/static/src/components/mis_report_widget.esm.js index 5b8db981f..a7e39f17b 100644 --- a/mis_builder/static/src/components/mis_report_widget.esm.js +++ b/mis_builder/static/src/components/mis_report_widget.esm.js @@ -9,6 +9,9 @@ import {SearchBar} from "@web/search/search_bar/search_bar"; import {parseDate} from "@web/core/l10n/dates"; import {registry} from "@web/core/registry"; import {standardFieldProps} from "@web/views/fields/standard_field_props"; +import {useSetupAction} from "@web/webclient/actions/action_hook"; + +export const misReportWidgetClassName = "mis_report_widget"; export class MisReportWidget extends Component { setup() { @@ -33,6 +36,18 @@ export class MisReportWidget extends Component { this.refresh(); }); onWillStart(this.willStart); + useSetupAction({ + getGlobalState: () => { + if (!this.showSearchBar) { + return {}; + } + return { + misReportSearchModelState: JSON.stringify( + this.searchModel.exportState() + ), + }; + }, + }); } // Lifecycle @@ -59,11 +74,15 @@ export class MisReportWidget extends Component { this.widget_show_pivot_date = result.widget_show_pivot_date; if (this.showSearchBar) { // Initialize the search model - await this.searchModel.load({ + const config = { resModel: this.source_aml_model_name, searchViewId: this.widget_search_view_id, analyticAccountId: this.analyticAccountId, - }); + }; + if (this.env.misReportSearchModelState) { + config.state = JSON.parse(this.env.misReportSearchModelState); + } + await this.searchModel.load(config); } // Compute the report @@ -232,9 +251,15 @@ MisReportWidget.props = { type: String, optional: true, }, + misReportSearchModelState: { + type: String, + optional: true, + }, +}; +MisReportWidget.extractProps = ({attrs}) => { + return { + analyticAccountIdField: attrs.analytic_account_id_field, + }; }; -MisReportWidget.extractProps = ({attrs}) => ({ - analyticAccountIdField: attrs.analytic_account_id_field, -}); -registry.category("fields").add("mis_report_widget", MisReportWidget); +registry.category("fields").add(misReportWidgetClassName, MisReportWidget); diff --git a/mis_builder/static/src/views/form/mis_report_form_controller.esm.js b/mis_builder/static/src/views/form/mis_report_form_controller.esm.js new file mode 100644 index 000000000..302a46708 --- /dev/null +++ b/mis_builder/static/src/views/form/mis_report_form_controller.esm.js @@ -0,0 +1,15 @@ +/** @odoo-module */ + +import {FormController} from "@web/views/form/form_controller"; +import {useSubEnv} from "@odoo/owl"; + +export class MisReportFormController extends FormController { + setup() { + super.setup(); + useSubEnv({ + misReportSearchModelState: + this.props.globalState && + this.props.globalState.misReportSearchModelState, + }); + } +} diff --git a/mis_builder/static/src/views/form/mis_report_form_view.esm.js b/mis_builder/static/src/views/form/mis_report_form_view.esm.js new file mode 100644 index 000000000..bedb6012b --- /dev/null +++ b/mis_builder/static/src/views/form/mis_report_form_view.esm.js @@ -0,0 +1,14 @@ +/** @odoo-module **/ + +import {MisReportFormController} from "@mis_builder/views/form/mis_report_form_controller.esm"; +import {formView} from "@web/views/form/form_view"; +import {registry} from "@web/core/registry"; + +// The view to use when mounting `mis_report_widget` widget in order to preserve the +// filters when returning from the drill-down views. +export const misReportFormView = { + ...formView, + Controller: MisReportFormController, +}; + +registry.category("views").add("mis_report_form_view", misReportFormView); diff --git a/mis_builder/views/mis_report_instance.xml b/mis_builder/views/mis_report_instance.xml index f13fce50e..c4c07228b 100644 --- a/mis_builder/views/mis_report_instance.xml +++ b/mis_builder/views/mis_report_instance.xml @@ -10,13 +10,14 @@ edit="false" create="false" delete="false" + js_class="mis_report_form_view" >