[IMP] web: allow linking to another model on graph and pivot views

This commit makes it simpler to override the action executed when
clicking on pivot cells or graph bars.
This is a nice to have for reports where we don't want to open the
report model but the model the report is based on.

TaskId-2764844

Part-of: odoo/odoo#85404
This commit is contained in:
William Braeckman
2022-03-14 17:28:13 +00:00
parent 74fa91e0b3
commit 54333236e3
2 changed files with 45 additions and 28 deletions
+25 -16
View File
@@ -67,11 +67,34 @@ export class GraphView extends Component {
};
}
/**
* Execute the action to open the view on the current model.
*
* @param {Array} domain
* @param {Array} views
* @param {Object} context
*/
openView(domain, views, context) {
this.actionService.doAction(
{
context,
domain,
name: this.model.metaData.title,
res_model: this.model.metaData.resModel,
target: "current",
type: "ir.actions.act_window",
views: views,
},
{
viewType: "list",
}
);
}
/**
* @param {string} domain the domain of the clicked area
*/
onGraphClicked(domain) {
const { context, resModel, title } = this.model.metaData;
const { context } = this.model.metaData;
Object.keys(context).forEach((x) => {
if (x === "group_by" || x.startsWith("search_default_")) {
@@ -87,21 +110,7 @@ export class GraphView extends Component {
return [views[viewType] || false, viewType];
}
const actionViews = [getView("list"), getView("form")];
this.actionService.doAction(
{
context,
domain,
name: title,
res_model: resModel,
target: "current",
type: "ir.actions.act_window",
views: actionViews,
},
{
viewType: "list",
}
);
this.openView(domain, actionViews, context);
}
/**
+20 -12
View File
@@ -115,6 +115,25 @@ export class PivotView extends Component {
onMeasureSelected({ measure }) {
this.model.toggleMeasure(measure);
}
/**
* Execute the action to open the view on the current model.
*
* @param {Array} domain
* @param {Array} views
* @param {Object} context
*/
openView(domain, views, context) {
this.actionService.doAction({
type: "ir.actions.act_window",
name: this.model.metaData.title,
res_model: this.props.resModel,
views: views,
view_mode: "list",
target: "current",
context,
domain,
});
}
/**
* @param {CustomEvent} ev
*/
@@ -142,18 +161,7 @@ export class PivotView extends Component {
colValues: cell.groupId[1],
originIndex: cell.originIndexes[0],
};
const domain = this.model.getGroupDomain(group);
this.actionService.doAction({
type: "ir.actions.act_window",
name: this.model.metaData.title,
res_model: this.props.resModel,
views: this.views,
view_mode: "list",
target: "current",
context,
domain,
});
this.openView(this.model.getGroupDomain(group), this.views, context);
}
}