odoo 通过button跳转到tree视图,并传递domain

本文介绍Odoo中两种按钮类型的使用方法:object与action。通过具体示例展示了如何利用这两种方式从一个视图跳转到另一个视图,并在跳转过程中传递domain参数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

odoo 通过button跳转到tree视图,并传递domain

跳转到视图的按钮类型,目前我知道的有两种,一种是object,即通过定义相应的方法来返回相关的视图,另一种是action,可以直接跳转到对应的视图

举例如下:

<button name="button_get_product_quantity" type="object" string="查询可用量"/>
<field name="id" invisible="1"/>
<button name="%(sale_order_line_part_action_tree)d" type="action" string="配件信息" context="{'default_order_line_id':id}"/>
<!--sale_order_line_part_action_tree 是一个窗口动作-->

第一种传递domain比较简单,可以直接在函数返回的动作视图中添加domain,domain 的数据可以直接在函数中获取,此处不再赘述
第二种传递domain需要借助context实现:

在原视图中的button设置context,本例中设置的上下文:context="{‘default_order_line_id’:id}"
在动作视图中将context 的值取出,context.get(‘default_order_line_id’, True),并定义到domain字段中:

<record id="sale_order_line_part_action_tree" model="ir.actions.act_window">
    <field name="name">sale.order.line.part.action</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">sale.order.line.part</field>
    <field name="view_mode">tree,form</field>
    <field name="view_type">form</field>
    <field name="domain">[('order_line_id','=',context.get('default_order_line_id', True))]</field>
    <field name="help" type="html">
    <field name="target">new</field>
        <p class="oe_view_nocontent_create">
            <!-- Add Text Here -->
        </p><p>
            <!-- More details about what a user can do with this object will be OK -->
        </p>
    </field>
</record>
Odoo是一个开源的企业资源规划(ERP)系统,其中包含了模块化的软件设计,用于管理企业中的各种业务流程。在Odoo中,form视图tree视图是两种常用的视图方式,分别用于展示数据的详细信息和列表信息。 在Odoo 17中,如果你想在form视图中嵌套一个tree视图且希望固定tree视图中的列宽度,你可以通过修改tree视图的XML定义来实现。通常,这涉及到使用Odoo的XML-RPC API或者直接编辑XML文件来定义视图。 要固定列宽,你可以在tree视图的XML定义中添加`colspan`属性来控制列宽。举个例子: ```xml <odoo> <record id="view_form_tree" model="ir.ui.view"> <field name="name">my.object.form.tree</field> <field name="model">my.object</field> <field name="arch" type="xml"> <form string="My Object"> <sheet> <!-- 其他form视图的元素 --> <tree string="Tree View" width="400"> <field name="field1" colspan="2"/> <!-- 这里的2代表这个字段占两个单元格的宽度 --> <field name="field2" colspan="3"/> <!-- 这里的3代表这个字段占三个单元格的宽度 --> <!-- 其他tree视图的字段 --> </tree> </sheet> </form> </field> </record> </odoo> ``` 在上述代码中,`<tree>` 标签的 `width` 属性设置为"400",指定了tree视图的整体宽度。`<field>`标签的 `colspan` 属性则用来控制每个字段占有的列数,从而实现固定列宽的效果。 需要注意的是,Odoo视图可以非常复杂,且可能受到很多因素的影响,如CSS样式和Odoo版本的具体实现,因此在实际操作中可能需要进一步的调试和定制。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值