Odoo v8中的嵌套树视图 [英] Nested Tree View in Odoo v8
问题描述
我有一个任务列表,每个任务可以有0 .. *个子任务.
i have a list of tasks and every task could have 0..* sub tasks.
我的模型当前如下所示:
My model currently looks like this:
label = fields.Char(string='Label')
parent_id = fields.Many2one('company.task', string='Super task')
sub_tasks = fields.One2many('company.task', 'parent_id', string='Sub tasks')
#skipped unnecessary parts
我想以分层的方式展示任务,就像这样:
I want to present the tasks in a hierarchical way, like this:
SuperTask1
SubTask1
SubTask2
SuperTask2
SubTask3
...
到目前为止,我拥有的XML看起来像这样:
The XML i have so far looks like this:
<!-- Task action window -->
<record id="action_list_task_complete" model="ir.actions.act_window">
<field name="name">Tasks</field>
<field name="res_model">company.task</field>
<field name="view_mode">tree,form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Create the first task</p>
</field>
</record>
<!-- Task tree -->
<record id="task_tree_window_view" model="ir.actions.act_window.view">
<field name="view_mode">tree</field>
<field name="view_id" ref="task_tree_view" />
<field name="act_window_id" ref="action_list_task_complete" />
</record>
<record id="task_tree_view" model="ir.ui.view">
<field name="name">company.task.tree</field>
<field name="model">company.task</field>
<field name="priority" eval="16"/>
<field name="field_parent">sub_tasks</field>
<field name="arch" type="xml">
<tree string="Task list" colors="blue:status=='not_processed';red:status=='delayed'">
<field name="label"/>
<field name="sub_tasks"/>
<field name="parent_id"/>
</tree>
</field>
</record>
显示视图时不考虑 field_parent .我在这里做错了什么?我查看了其他类似的问题和文档,但所有这些似乎仅适用于不同版本的odoo.
The field_parent isn't taken into account when displaying the view. What am I doing wrong here? I looked at other similar questions and and the documentation but all these seem to work only for different versions of odoo.
有人知道吗?
关于,F
推荐答案
在操作定义中,应将view_type
字段设置为tree
(默认为form
):
In your action definition, you should set the view_type
field to tree
(by default it's form
):
<field name="view_type">tree</field>
并删除view_mode
,因为当view_type
为tree
由于对旧代码的不良命名(由于向后兼容性原因而仍然存在),这一切都非常令人困惑.
It's all very confusing because of bad naming of legacy code which is still present for backward compatibility reasons.
-
view_type = form,view_mode = tree实际上是 list 视图(表格可视化),不支持真正的树导航(展开/折叠分支)
view_type = form, view_mode = tree is actually the list view (the table visualization) which doesn't support real tree navigation (expanding / collpasing the branches)
view_type = tree,(忽略view_mode)是真实的" 树视图
view_type = tree, (view_mode is ignored) is the "real" tree view
您可以在旧文档中阅读此内容,即使它并不能完全清楚地显示按类别的产品
You can read this in the old doc, even though it doesn't make it clear at all https://doc.odoo.com/6.0/developer/2_7_menu_action/7_2_actions/
And you can see as an example the action definition of one of the few tree views in Odoo, Products by category
这篇关于Odoo v8中的嵌套树视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!