Compare commits
5 commits
18.0
...
16.0-hiera
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2412827811 | ||
|
|
75d7cecec8 | ||
|
|
d2a4980ac1 | ||
|
|
43d2ed0172 | ||
|
|
8cf4d716b3 |
11 changed files with 181 additions and 0 deletions
1
bemade_hierarchical_tree_view/__init__.py
Normal file
1
bemade_hierarchical_tree_view/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import models
|
||||
36
bemade_hierarchical_tree_view/__manifest__.py
Normal file
36
bemade_hierarchical_tree_view/__manifest__.py
Normal 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
|
||||
}
|
||||
1
bemade_hierarchical_tree_view/models/__init__.py
Normal file
1
bemade_hierarchical_tree_view/models/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from . import ir_ui_view
|
||||
18
bemade_hierarchical_tree_view/models/ir_ui_view.py
Normal file
18
bemade_hierarchical_tree_view/models/ir_ui_view.py
Normal 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'},
|
||||
)
|
||||
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
|
|
@ -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);
|
||||
|
|
@ -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";
|
||||
|
|
@ -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>
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
/** @odoo-module **/
|
||||
|
||||
import { ListRenderer } from "@web/views/list/list_renderer";
|
||||
|
||||
export class HierarchicalTreeViewRenderer extends ListRenderer {
|
||||
|
||||
}
|
||||
35
bemade_hierarchical_tree_view/static/src/components/view.js
Normal file
35
bemade_hierarchical_tree_view/static/src/components/view.js
Normal 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);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
22
bemade_hierarchical_tree_view/views/res_partner.xml
Normal file
22
bemade_hierarchical_tree_view/views/res_partner.xml
Normal 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>
|
||||
Loading…
Reference in a new issue