首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Odoo 9的“销售订单表单”视图中隐藏“确认销售”按钮

在Odoo 9的“销售订单表单”视图中隐藏“确认销售”按钮
EN

Stack Overflow用户
提问于 2016-10-21 06:45:57
回答 3查看 2.5K关注 0票数 2

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

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

代码语言:javascript
运行
复制
<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}"/>

我想把这两个按钮都藏起来。所以我尝试了下面的代码。

代码语言:javascript
运行
复制
<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>

我还尝试了以下属性:

代码语言:javascript
运行
复制
<attribute name="states"></attribute>

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

问题:

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

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-10-21 07:13:22

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

另一个很好的例子(可能不再适用于Odoo 9)是在sale.order.line窗体视图的name字段后面设置一个新的sale.order字段。表单视图如下所示:

代码语言:javascript
运行
复制
<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将导致目标。

代码语言:javascript
运行
复制
<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>

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

代码语言:javascript
运行
复制
<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
票数 5
EN

Stack Overflow用户

发布于 2016-12-24 16:12:05

你可以使用xpath。

代码语言:javascript
运行
复制
button[@name='action_confirm'][1]

xpath。

代码语言:javascript
运行
复制
button[@name='action_confirm'][2]

希望它能帮上忙

票数 0
EN

Stack Overflow用户

发布于 2020-12-29 09:06:21

** Odoo 12

除了@CZoellner的答案,对于Odoo 12,它在view_order_form上的定义更改为

代码语言:javascript
运行
复制
<button name="action_confirm" id="action_confirm"
    string="Confirm" class="btn-primary" type="object"
    attrs="{'invisible': [('state', 'not in', ['sent'])]}"/>
<button name="action_confirm"
    string="Confirm" type="object"
    attrs="{'invisible': [('state', 'not in', ['draft'])]}"/>

请注意,在此更改中,不再存在states属性。因此,为了隐藏这两个按钮,我们可以使用

代码语言:javascript
运行
复制
<xpath expr="//button[@name='action_confirm'][1]" position="attributes">
    <attribute name="attrs"></attribute>
    <attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//button[@name='action_confirm'][2]" position="attributes">
    <attribute name="attrs"></attribute>
    <attribute name="invisible">1</attribute>
</xpath>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40170027

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档