Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
4 Răspunsuri
13485 Vizualizări

Hi, in my case i want to create a button inside tree view header to call an existing wizard. my source code is working, but i need to select some record to show my custom button. did missing something or this is a wrong way to create custom button on tree view header?

tree_view.xml

<record id="view_bank_account_tree"model="ir.ui.view">
    <field name="name">bank.account.treefield>
    <field name="model">account.journalfield>
<field name="type">treefield>
<field name="arch"type="xml">
        <tree create='0'string="Bank Account">
         <header>
                <button name="show_wizard"type="object"string="Create"class="oe_highlight"/>
            header>
            <field name="name"/>
            <field name="bank_id"/>
            <field name="bank_bic"/>
        tree>
    field>
record>

model.py

from odoo import models, fields, api

class bank_account(models.Model):
    _inherit='account.journal'
    bank_bic=fields.Char(string='Bank Identifier Code', related='bank_id.bic')

    def show_wizard(self):
    return {
        'name' : 'Add a Bank Account',
        'type' : 'ir.actions.act_window',
        'res_model' : 'account.setup.bank.manual.config',
        'views' : [[False, 'form']],
        'target' : 'new'
}
Imagine profil
Abandonează
Cel mai bun răspuns
For odoo15 Follow this tutorial 

www.cybrosys.com/blog/how-to-add-a-create-button-near-tree-kanban-view-in-odoo-15

For odoo16 Follow the same tutorial 

But put your xml and js files in assets_backend bundle
and then change o_list_button_button to o_list_button_add

 

<t t-extend="ListView.buttons" t-name="some_unique_name">
        <t t-jquery="button.o_list_button_add" t-operation="after">
            <button type="button" class="btn btn-primary open_wizard_action">
                    Open Wizard
            </button>
        </t>
    </t> 


       
           
       
     

    

           

       

   


Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

Inorder to make a button in the tree view, first you need to create an xml extending the list view buttons.

<templates id="template" xml:space="preserve">


    <t t-extend="ListView.buttons">


        <t t-jquery="div.o_list_buttons" t-operation="append">


            <button type="object" class="btn  btn-class">


                /* button name */


            </button>


        </t>


    </t>


</templates>


And then, you need to add a js file and include the button in ListController and setup the action.

var ListController = require("web.ListController");
var includeEdit = {

renderButtons: function() {
this._super.apply(this, arguments);
this.$buttons.find('button.btn-class').click(this.proxy('btn_function'));
}
},
 
btn_function: function() {
var action = {
type: "ir.actions.act_window",
name: /* Name of Wizard*/,
res_model: /* Wizard Model */,
views: [[false,'form']],
target: 'new',
view_type : 'form',
view_mode : 'form',
context : {/* Context to be passed */},
}
return this.do_action(action);
},
}
ListController.include(includeEdit);
});

Regards

Imagine profil
Abandonează
Autor Cel mai bun răspuns

thank you, it works correctly but since odoo has default create button and when I try to append it. My tree view shows 2 button create, one from default odoo and the other is custom from mine. is it possible if adding condition on my button? i want my custom button will apear only on my tree and make odoo default button invisible

Imagine profil
Abandonează
Cel mai bun răspuns

simplest solution for this need is to use   display="always" in button

Example:

 <tree>          

​<header>            

​<button name="action_do_something" string="Button text"             

​type="object" display="always"          

​class="btn-primary">

​</button>          

​</header>

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
mai 24
1831
1
feb. 17
5553
1
nov. 16
5824
1
ian. 16
7254
1
mar. 15
16027