Скрыть кнопку «Подтвердить продажу» в форме заказа на продажу в Odoo 9

Я использую версию сообщества 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>

С приведенным выше кодом это только первая кнопка скрытия/влияния.

Вопрос:

Как скрыть обе кнопки Подтвердить продажу?


person Bhavesh Odedra    schedule 21.10.2016    source источник


Ответы (3)


Механизм без xpath влияет только на первое попадание. Вот почему вы должны использовать здесь xpath.

Еще один хороший пример (возможно, уже не для Odoo 9) — установка нового поля sale.order.line за полем name в представлении формы sale.order. Вид формы примерно такой:

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

Итак, чтобы ответить на ваш вопрос напрямую (EDIT):

<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
person CZoellner    schedule 21.10.2016

можно использовать xpath...

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

путь ...

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

Надеюсь, поможет

person user3558770    schedule 24.12.2016

**Для 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>
person ejabu    schedule 29.12.2020