Skip to content

Commit

Permalink
[IMP] mis_builder: preserve the filters when navigating back from dri…
Browse files Browse the repository at this point in the history
…ll-down

Prior to this commit the state of the searchModel was lost when navigating
back from a drill-down.

This commit uses the globalState in order to store and restore the state
of the searchModlel. The use of a SubEnv allows not having to pass props
up to the widget, which would have required overriding the renderer, the
compiler and field.
  • Loading branch information
Laurent Stukkens committed Dec 28, 2023
1 parent 9a8add9 commit 7c2fc76
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 8 deletions.
3 changes: 2 additions & 1 deletion mis_builder/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 31 additions & 6 deletions mis_builder/static/src/components/mis_report_widget.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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);
Original file line number Diff line number Diff line change
@@ -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,
});
}
}
14 changes: 14 additions & 0 deletions mis_builder/static/src/views/form/mis_report_form_view.esm.js
Original file line number Diff line number Diff line change
@@ -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);
3 changes: 2 additions & 1 deletion mis_builder/views/mis_report_instance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
edit="false"
create="false"
delete="false"
js_class="mis_report_form_view"
>
<sheet>
<field
name="id"
widget="mis_report_widget"
nolabel="1"
style="width:100%"
class="w-100"
/>
</sheet>
</form>
Expand Down

0 comments on commit 7c2fc76

Please sign in to comment.