【问题标题】:Hide "Confirm Sale" button in Sale Order form view in Odoo 9在 Odoo 9 的销售订单表单视图中隐藏“确认销售”按钮
【发布时间】:2017-03-03 08:59:06
【问题描述】:

我正在使用 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}"/>

我试图从视图中隐藏这两个按钮。所以我尝试了以下代码。

<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>

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

问题:

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

【问题讨论】:

    标签: openerp odoo-9 odoo-view


    【解决方案1】:

    **对于 Odoo 12

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

    <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 属性。所以,要隐藏这两个按钮,我们可以使用

    <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>
    

    【讨论】:

      【解决方案2】:

      你可以使用 xpath ...

      button[@name='action_confirm'][1]
      

      xpath ...

      button[@name='action_confirm'][2]
      

      希望对你有帮助

      【讨论】:

        【解决方案3】:

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

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

        <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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-07-23
          • 1970-01-01
          相关资源
          最近更新 更多