Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] mis_builder: preserve the filters when navigating back from drill-down #593

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mis_builder/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"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",
Expand Down
33 changes: 28 additions & 5 deletions mis_builder/static/src/components/mis_report_widget.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import {Component, onWillStart, useState, useSubEnv} from "@odoo/owl";
import {useBus, useService} from "@web/core/utils/hooks";
import {DatePicker} from "@web/core/datepicker/datepicker";
import {Domain} from "@web/core/domain";
import {FilterMenu} from "@web/search/filter_menu/filter_menu";
import {SearchBar} from "@web/search/search_bar/search_bar";
import {SearchModel} from "@web/search/search_model";
import {parseDate} from "@web/core/l10n/dates";
import {registry} from "@web/core/registry";
import {useSetupAction} from "@web/webclient/actions/action_hook";

export class MisReportWidget extends Component {
setup() {
Expand All @@ -32,6 +34,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 @@ -58,10 +72,14 @@ 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,
});
};
if (this.env.misReportSearchModelState) {
config.state = JSON.parse(this.env.misReportSearchModelState);
}
await this.searchModel.load(config);
}

// Compute the report
Expand Down Expand Up @@ -104,11 +122,16 @@ export class MisReportWidget extends Component {
}

get context() {
var ctx = super.context;
if (this.showSearchBar) {
let ctx = this.props.record.context;
if (this.showSearchBar && this.searchModel.searchDomain) {
ctx = {
...ctx,
mis_analytic_domain: this.searchModel.searchDomain,
mis_analytic_domain: Domain.and([
new Domain(
this.props.record.context.mis_analytic_domain || Domain.TRUE
),
new Domain(this.searchModel.searchDomain),
]).toList(),
};
}
if (this.showPivotDate && this.state.pivot_date) {
Expand Down
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
Loading