1

In odoo 15, i've created a button in tree view, but it not always visible, i must click on a record in the tree view to make the button appear.

enter image description here enter image description here

My code:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <record id="grabfood_orders_tree" model="ir.ui.view">
            <field name="name">grabfood.orders.tree</field>
            <field name="model">grabfood.orders</field>
            <field name="arch" type="xml">
                <tree create="false">
                    <header>
                        <button string="Read GrabFood API" name="action_read_grabfood_api" type="object" class="btn-primary"/>
                    </header>
                    <field name="name"/>
                </tree>
            </field>
        </record>
    </data>
</odoo>

Please help, thanks.

fudu
  • 617
  • 1
  • 10
  • 19
  • What is the use case for this requirement I am curious – Muhammad Yusuf Jan 25 '22 at 06:20
  • I just wanna create a button to run an action, but with above code, the button is always invisible unless i click on the records. The action i wanna do is to run an API and return the result. – fudu Jan 25 '22 at 06:35
  • There might be an easy way in odoo 15 but with my knowledge, I would ask you refer mrp_mps module button "Add a product" https://demo3.odoo.com/web#cids=1&action=1186&menu_id=866 you will need to use JS snippet which could be tricky and from js call your function that is calling the api It's enterprise code – Muhammad Yusuf Jan 25 '22 at 12:45
  • thanks @MuhammadYusuf, i will try your solution and report to you as soon as posible. – fudu Jan 26 '22 at 02:53
  • @MuhammadYusuf, i don't see "add a product" button in Manufacture module – fudu Jan 26 '22 at 04:05
  • Oh, i've found it, it's inside odoo-enterprise version. – fudu Jan 26 '22 at 04:27
  • @fudu did you solve this? – Dominik Mar 31 '22 at 07:23
  • @Dominik not yet, this is hard to do, and with alot of custom js, which i'm not able to handle because i'm still new for this. – fudu Mar 31 '22 at 09:20

1 Answers1

0

Try this: https://github.com/Tlki/web_tree_header_buttons_always_visible

    <?xml version="1.0" encoding="utf-8"?>
    <odoo>
        <data>
            <record id="grabfood_orders_tree" model="ir.ui.view">
                <field name="name">grabfood.orders.tree</field>
                <field name="model">grabfood.orders</field>
                <field name="arch" type="xml">
                    <tree create="false">
                        <header>
                            <button string="Read GrabFood API" 
         name="action_read_grabfood_api" type="object" class="btn-primary"
    attrs="{'always_visible': True}"
    />
                        </header>
                        <field name="name"/>
                    </tree>
                </field>
            </record>
        </data>
    </odoo>
Don
  • 3,876
  • 10
  • 47
  • 76