gpt4 book ai didi

odoo - 在 Odoo 9 的销售订单表单 View 中隐藏 "Confirm Sale"按钮

转载 作者:行者123 更新时间:2023-12-02 20:56:16 25 4
gpt4 key购买 nike

我正在使用 Odoo 9 社区版本。

在销售订单表单中有以下按钮:

<button name="action_confirm" states="sent" string="Confirm Sale" class="btn-primary" type="object" context="{'show_sale': True}"/>
<button name="action_confirm" states="draft" string="Confirm Sale" type="object" context="{'show_sale': True}"/>

我试图从 View 中隐藏这两个按钮。所以我尝试使用以下代码。

<record model="ir.ui.view" id="hide_so_confirm_button_form">
<field name="name">hide.so.confirm.button.form</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_order_form"/>
<field name="arch" type="xml">
<button name="action_confirm" position="attributes">
<attribute name="invisible">1</attribute>
</button>
</field>
</record>

我还尝试了以下属性:

<attribute name="states"></attribute>

使用上面的代码,它只是隐藏/影响第一个按钮。

问题:

如何隐藏两个确认销售按钮?

最佳答案

没有xpath的机制只影响第一次命中。这就是为什么你必须在这里使用 xpath。

另一个很好的例子(可能不再适用于 Odoo 9)是在 sale.order< 上的 name 字段后面设置一个新的 sale.order.line 字段 表单 View 。表单 View 是这样的:

<form>
<field name="name" /> <!-- sale.order name field -->
<!-- other fields -->
<field name="order_line">
<form> <!-- embedded sale.order.line form view -->
<field name="name" />
<!-- other fields -->
</form>
<tree> <!-- embedded sale.order.line tree view -->
<field name="name" />
<!-- other fields -->
</tree>
</field>
<form>

使用您的方式可以尝试在 sale.order name 字段后面设置新字段(在此示例中)。使用 xpath 将达到目标。

<xpath expr="//form//tree//field[@name='name']" position="after">
<field name="new_field" />
</xpath>
<xpath expr="//form//form//field[@name='name']" position="after">
<field name="new_field" />
</xpath>

因此,直接回答您的问题(编辑):

<xpath expr="//button[@name='action_confirm' and @states='sent']" position="attributes">
<attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
<attribute name="invisible">1</attribute>
</xpath
<xpath expr="//button[@name='action_confirm' and @states='draft']" position="attributes">
<attribute name="states" /> <!-- delete states attribute, it's influencing invisible behaviour -->
<attribute name="invisible">1</attribute>
</xpath

关于odoo - 在 Odoo 9 的销售订单表单 View 中隐藏 "Confirm Sale"按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40170027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com