Compare commits

...

5 commits

Author SHA1 Message Date
Marc Durepos
2412827811 Get rid of with_search, use view.js instead. 2023-12-18 15:15:41 -05:00
Marc Durepos
75d7cecec8 htree view is now displaying just like a tree.
More functionality to come now!
2023-12-13 08:50:32 -05:00
Marc Durepos
d2a4980ac1 more progress made getting a hierarchical tree view defined 2023-12-12 21:07:33 -05:00
Marc Durepos
43d2ed0172 Some initial code to hook into the WithSearch component and check if we are using a HierarchicalListViewController. 2023-12-12 16:36:48 -05:00
Marc Durepos
8cf4d716b3 first branch commit for bemade_hierarchical_tree_view. 2023-12-12 14:49:53 -05:00
11 changed files with 181 additions and 0 deletions

View file

@ -0,0 +1 @@
from . import models

View file

@ -0,0 +1,36 @@
#
# Bemade Inc.
#
# Copyright (C) 2023-June Bemade Inc. (<https://www.bemade.org>).
# Author: Marc Durepos (Contact : mdurepos@durpro.com)
#
# This program is under the terms of the Odoo Proprietary License v1.0 (OPL-1)
# It is forbidden to publish, distribute, sublicense, or sell copies of the Software
# or modified copies of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
{
'name': 'Hierarchical Tree View',
'version': '16.0.1.0.0',
'summary': 'Creates a new view type "htree" to be used when defining views',
'category': 'Technical',
'author': 'Bemade Inc.',
'website': 'http://www.bemade.org',
'license': 'OPL-1',
'depends': ['web', 'contacts'],
'data': ['views/res_partner.xml'],
'assets': {
'web.assets_backend': [
'bemade_hierarchical_tree_view/static/src/*/**',
]
},
'installable': True,
'auto_install': False
}

View file

@ -0,0 +1 @@
from . import ir_ui_view

View file

@ -0,0 +1,18 @@
from odoo import models, fields
class View(models.Model):
_inherit = "ir.ui.view"
type = fields.Selection(
selection_add=[('htree', 'Hierarchical Tree')]
)
class ActionView(models.Model):
_inherit = "ir.actions.act_window.view"
view_mode = fields.Selection(
selection_add=[('htree', 'Hierarchical Tree')],
ondelete={'htree': 'cascade'},
)

View file

@ -0,0 +1,10 @@
/** @odoo-module **/
import { ListArchParser } from "@web/views/list/list_arch_parser";
export class HierarchicalTreeArchParser extends ListArchParser {
parse(arch, models, modelName) {
let modifiedArch = arch.replaceAll("htree", "tree");
return super.parse(modifiedArch, models, modelName);
}
};

View file

@ -0,0 +1,20 @@
/** @odoo-module **/
import { listView } from "@web/views/list/list_view";
import { HierarchicalTreeViewController } from "./hierarchical_tree_view_controller";
import { HierarchicalTreeViewRenderer } from "./hierarchical_tree_view_renderer";
import { registry } from "@web/core/registry";
import {HierarchicalTreeArchParser} from "./hierarchical_tree_arch_parser";
const HierarchicalTreeView = {
...listView,
type: "htree",
display_name: "Hierarchical Tree",
icon: "fa fa-sitemap",
accessKey: "h",
Controller: HierarchicalTreeViewController,
Renderer: HierarchicalTreeViewRenderer,
ArchParser: HierarchicalTreeArchParser,
}
registry.category("views").add("htree", HierarchicalTreeView);

View file

@ -0,0 +1,25 @@
/** @odoo-module **/
import { ListController } from "@web/views/list/list_controller";
import { onWillRender } from "@odoo/owl";
export class HierarchicalTreeViewController extends ListController {
setup() {
super.setup();
onWillRender(() => {
console.log("Test");
});
}
}
HierarchicalTreeViewController.props = {
...ListController.props,
parentField: {type: String, optional: true},
childField: {type: String, optional: true},
}
HierarchicalTreeViewController.defaultProps = {
...ListController.defaultProps,
parentField: 'parent_id',
childField: 'child_id',
}
HierarchicalTreeViewController.template = "web.HierarchicalTreeView";

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="web.HierarchicalTreeView" owl="1" t-inherit="web.ListView" t-inherit-mode="primary">
</t>
</templates>

View file

@ -0,0 +1,7 @@
/** @odoo-module **/
import { ListRenderer } from "@web/views/list/list_renderer";
export class HierarchicalTreeViewRenderer extends ListRenderer {
}

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

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="res_partner_view_htree" model="ir.ui.view">
<field name="name">res.partner.view.htree</field>
<field name="model">res.partner</field>
<field name="arch" type="xml">
<htree>
<field name="name"/>
<field name="email" widget="email"/>
</htree>
</field>
</record>
<record id="contacts.action_contacts" model="ir.actions.act_window">
<field name="view_mode">kanban,tree,form,activity,htree</field>
</record>
<record id="action_contacts_view_htree" model="ir.actions.act_window.view">
<field name="sequence" eval="5"/>
<field name="view_mode">htree</field>
<field name="view_id" ref="res_partner_view_htree"/>
<field name="act_window_id" ref="contacts.action_contacts"/>
</record>
</odoo>