Oejia 技术栈
首页
应用市场
方案
OE学院
分享
关于
编辑器
登录
Odoo 增加树形列表视图的支持
admin
on 2022-12-29
定义抽象基类模型 ``` class TreeModel(models.AbstractModel): _name = 'ext.tree' _description = u'树表' _field_parent = None @api.model def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None): records = super(TreeModel, self).search_read(domain, fields, offset, limit, order) m_dict = {} path_dict = {} for r in records: m_dict[r['id']] = r def get_path(node,id_path=None): _id = node['id'] if _id in path_dict: return path_dict[_id] path = [] if self._field_parent in node and node[self._field_parent]: p_id = node[self._field_parent][0] p_node = m_dict.get(p_id,None) if p_node: p_path = get_path(p_node) path = p_path + [str(_id)] else: path = [] else: path = [str(_id)] path_dict[_id] = path return path for r in records: r['__path'] = ','.join( get_path(r) ) records.sort(key=lambda x: x['__path'])#(cmp=lambda x,y:cmp(x['__path'],y['__path'])) return records ``` 模型使用示例 ``` class HrDepartment(models.Model): _name = 'hr.department' _inherit = ['hr.department', 'ext.tree'] _field_parent = 'parent_id' ``` 前端扩展 ``` <odoo> <data> <template id="assets_backend" name="base extension assets" inherit_id="web.assets_backend"> <xpath expr="." position="inside"> <link rel="stylesheet" type="text/css" href="/oejia_ext/static/lib/jquery.treegrid/css/jquery.treegrid.css"/> <script type="text/javascript" src="/base_ext/static/src/js/list_renderer.js"/> <script type="text/javascript" src="/oejia_ext/static/lib/jquery.treegrid/js/jquery.treegrid.js"></script> <script type="text/javascript" src="/oejia_ext/static/lib/jquery.treegrid/js/jquery.treegrid.bootstrap3.js"></script> </xpath> </template> </data> </odoo> ``` list_renderer.js 关键内容 ``` odoo.define('base_ext.list_render', function (require) { "use strict"; var core = require('web.core'); var ListRenderer = require('web.ListRenderer'); ListRenderer.include({ _onRowClicked: function (event) { if ('no_row_click' in this.state.context){ }else{ this._super.apply(this, arguments); } }, init: function (parent, state, params) { this._super.apply(this, arguments); this.hasSelectors = false; }, _renderRow: function (record) { var $tr = this._super.apply(this, arguments); if ('field_parent' in this.state.context){ var field_parent = this.state.context.field_parent; var parent_id = null; if(record.data[field_parent]){ parent_id = record.data[field_parent].res_id; } $tr.addClass('treegrid-' + record.data.id); if(parent_id){ $tr.addClass('treegrid-parent-' + parent_id); } } return $tr; }, _renderView: function () { var res = this._super.apply(this, arguments); if ('field_parent' in this.state.context){ this.$el.find('.o_list_view').treegrid({ treeColumn: 0, expanderExpandedClass: 'fa fa-chevron-down', expanderCollapsedClass: 'fa fa-chevron-right' }); } return res; } }); return ListRenderer; }); ```
Information
Odoo 增加树形列表视图的支持
http://www.oejia.net/article/4314d33cf6434fa5996658502627b86b
http://www.oejia.net/raw/4314d33cf6434fa5996658502627b86b
admin
on 2022-12-29
Category
Odoo
Related
2016-11-22 :
Odoo 即时消息和通知相关的模块探究
2019-01-30 :
Odoo后端性能优化之—取消当访问页面404时对ir.attachment表的查询
2018-10-17 :
Odoo 11 到 Odoo 12 安装的依赖环境变化
2022-10-06 :
Odoo 16 正式发布时间
2018-10-24 :
Odoo 12 账号相关的变化
2018-02-08 :
如何自定义扩展Odoo前端控件widget
2016-03-12 :
Odoo 微信模块 Oejia_wx 基本使用说明
2017-08-11 :
DjangoX 多对多嵌入表单 Inline 的用法
2020-03-31 :
Odoo 企业微信的OA审批及移动化办公
2016-02-25 :
待整理
官方订阅号
关注订阅实时了解我们更多分享
分类
(20)
Django (3)
DjangoX (13)
JS (2)
Nginx (1)
Odoo (134)
Python (1)
YouMd (3)
公告说明 (2)
前端 (2)
后端HTTP (7)
异常处理 (1)
桌面UI (1)
移动开发 (4)
About This Entry
Odoo 让 server action 显示到指定的视图上
Odoo 16 正式发布时间
About This Blog
main index
to find recently
archives
to find all
标签
微信模块发布记录
微信模块
小程序商城
Web
Http
客服系统
OE商城
审批OA
HTML5
Markdown
DjangoX
markdown
PyQT
Python
示例
md
YouPBX
oeshop
服系统
Excel
解析
最近发布
OSError [Errno 5] Input/output error 异常处理
Odoo context 的常见使用示例
Odoo 符合国人菜单导航习惯的后台主题,支持最新的Odoo17、16等版本,支持企业版!
Odoo 官方应用市场开启 Odoo17 应用的发布!增加了行业应用专栏
Odoo商城模块 Oejia_weshop v1.2 发布,多商户、分销增强,增加商家端!
处理 Error Failed to download metadata for repo ‘appstream‘ Cannot prepare internal mirrorlist
Odoo 16 关键变化 change the term "acquirer" to "provider"
企业微信错误码 81013 的排查与处理
微信模块 Oejia_wx v0.6.7 发布,支持 Odoo16 及新的Websocket消息模式
Friend Links
Oejia技术梦博客分享
YouMd,爱上MarkDown
Mole轻量级wsgi架子