Get rid of with_search, use view.js instead.

This commit is contained in:
Marc Durepos 2023-12-18 15:15:41 -05:00
parent 75d7cecec8
commit 2412827811
2 changed files with 35 additions and 34 deletions

View file

@ -0,0 +1,35 @@
/** @odoo-module **/
import { View } from "@web/views/view";
import { patch } from "@web/core/utils/patch";
import { HierarchicalTreeViewController } from "./hierarchical_tree_view_controller";
import { onWillRender } from "@odoo/owl";
patch(View.prototype, "bemade_hierarchical_tree_view.View", {
setup() {
this._super();
/*
If we're rendering a hierarchical tree view, we need to remove the parent and
child fields from the groupBy parameters we pass down through the component
tree. This is necessary since this view type will treat the parent and child
groupings differently. We do it here instead of doing it in the controller
because the Controller would have to either modify its props or seriously
redefine the data used within the template, which we are trying to avoid for
code duplication reasons.
*/
if ( this.Controller.prototype === HierarchicalTreeViewController.prototype ) {
onWillRender(() => {
let parentField = this.Controller.parentField
let childField = this.Controller.childField
let parentIndex = this.groupBy.indexOf(parentField);
let childIndex = this.groupBy.indexOf(childField);
if (parentIndex) {
this.groupBy.splice(parentIndex, 1);
}
if (childField) {
this.groupBy.splice(childIndex, 1);
}
});
}
},
});

View file

@ -1,34 +0,0 @@
/** @odoo-module **/
import {patch} from "@web/core/utils/patch";
import {WithSearch} from "@web/search/with_search/with_search";
import {onWillRender} from "@odoo/owl";
import {HierarchicalTreeViewController} from "./hierarchical_tree_view_controller";
patch(WithSearch.prototype, "bemade_hierarchical_tree_view/with_search", {
setup() {
onWillRender(() => {
let children = Object.hasOwn(this.__owl__, 'children') ? this.__owl__.children : null;
if (children && Object.keys(children).length !== 0) {
for (let childProp in children) {
let child = children[childProp];
if (Object.hasOwn(child, 'component')) {
let childComponent = child.component;
if (childComponent.prototype == HierarchicalTreeViewController.prototype) {
let parentField, childField = (childComponent.parentField, childComponent.childField)
let parentIndex = this.groupBy.indexOf(parentField);
let childIndex = this.groupBy.indexOf(childField);
if (parentIndex) {
this.groupBy.splice(parentField, 1);
}
if (childField) {
this.groupBy.splice(childField, 1);
}
}
}
}
}
});
this._super();
}
});