Skip to content

Commit

Permalink
[IMP] mis_builder: take field context into account
Browse files Browse the repository at this point in the history
Prior to this commit only the action context was taken into account
when looking for the `mis_analytic_domain` key in the context.

This commit adds the support of the field context, where `self`
can be used in order to inject record data in the context.
  • Loading branch information
Laurent Stukkens committed Jan 16, 2024
1 parent b0692f8 commit 62e6e29
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions mis_builder/static/src/components/mis_report_widget.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ 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 {evaluateExpr} from "@web/core/py_js/py";
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";
Expand Down Expand Up @@ -121,15 +122,54 @@ export class MisReportWidget extends Component {
}
}

/**
* The domain built from both the context that is passed through the action
* and the one that is set on the field in the view. The last one being evaluated
* against the context populated with a self property populated with the record data.
*
* @returns Domain
*/
get misc_analytic_domain() {
let domain = Domain.TRUE;
const domain_mis_analytic_domain_key = "mis_analytic_domain";
// Get the domain that is set on the action
const record_context = this.props.record.context;
if (domain_mis_analytic_domain_key in record_context) {
const record_domain = new Domain(record_context.mis_analytic_domain);
domain = Domain.and([domain, record_domain]);
}
// Get the domain that is set on the field and evaluate it with both the context
// and the record data mounted on a self property.
if ("context" in this.props.record.activeFields[this.props.name]) {
const context_attr =
this.props.record.activeFields[this.props.name].context;
const evaluation_context = {
...record_context,
self: this.props.record.data,
};
const field_context = evaluateExpr(context_attr, evaluation_context);
if (domain_mis_analytic_domain_key in field_context) {
const field_domain = new Domain(field_context.mis_analytic_domain);
domain = Domain.and([domain, field_domain]);
}
}
return domain;
}

get context() {
let ctx = this.props.record.context;
const mis_analytic_domain = this.misc_analytic_domain;
if (mis_analytic_domain !== Domain.TRUE) {
ctx = {
...ctx,
mis_analytic_domain: mis_analytic_domain.toList(),
};
}
if (this.showSearchBar && this.searchModel.searchDomain) {
ctx = {
...ctx,
mis_analytic_domain: Domain.and([
new Domain(
this.props.record.context.mis_analytic_domain || Domain.TRUE
),
new Domain(ctx.mis_analytic_domain || Domain.TRUE),
new Domain(this.searchModel.searchDomain),
]).toList(),
};
Expand Down

0 comments on commit 62e6e29

Please sign in to comment.