How to add a button on a tree inside a form in Odoo 10?

I want to add a button to the order_line tree in the sales form, I added the following:

<xpath expr="/form/sheet/notebook/page[1]/field[@name='order_line']/tree/field[@name='price_subtotal']" position="after">
    <button name="%{action_view_wizard}d" string="" type="action" icon="fa-archive" attrs="{'invisible':[('product_id','=', False)]}"/>
</xpath>

And the master is defined

<record id="check_stock" model="ir.ui.view">
    <field name="name">sale_warehouse.check_stock_wizard</field>
    <field name="model">sale_warehouse.check_stock_wizard</field>
    <field name="arch" type="xml">
        <form string="Stock by warehouse">
            <group col="1">
                <field name="stock" nolabel="1"/>
            </group>
            <footer>
                <button string="Close" class="btn-default" special="cancel" />
            </footer>
        </form>
    </field>
</record>

<record id="action_view_wizard" model="ir.actions.act_window">
    <field name="name">Stock by warehouse</field>
    <field name="type">ir.actions.act_window</field>
    <field name="res_model">sale_warehouse.check_stock_wizard</field>
    <field name="view_type">form</field>
    <field name="view_mode">form</field>
    <field name="view_id" ref="check_stock"/>
    <field name="target">new</field>
</record>

The button is added normally, but its loading is disabled, so when I click the wizard there is no call, if I remove the button from the tree, the wizard is called ok, but I need to call from order_line because I need to transfer the context using the product_id line to get a margin on each stock.

I am using odoo10. What am I doing wrong?

+4
source share
1 answer

Try the following:

<xpath expr="/form/sheet/notebook/page[1]/field[@name='order_line']/tree position="inside">
    <button name="open_view_wizard" string="" type="object" icon="fa-archive" attrs="{'invisible':[('product_id','=', False)]}"/>
</xpath>

open_view_wizard sale : (, , ).

def open_view_wizard(self, cr, uid, ids, context=None):

            return {
                'view_type': 'form',
                'view_mode': 'form',
                'res_model': 'sale_warehouse.check_stock_wizard',
                'type': 'ir.actions.act_window',
                'context': context
            }
+1

Source: https://habr.com/ru/post/1663133/


All Articles