This question has been flagged
4 Replies
16778 Views

Hi everyone i am new at openerp and i wanna ask that how can i add new button above tree view(not in tree row)? my code for tree view:

<record model="ir.ui.view" id="orders_tree_view"> <field name="name">Orders Tree View</field> <field name="model">cm.orders</field> <field name="arch" type="xml"> <tree string="Orders Tree"> <field name="no"/> <field name="status"/> <field name="Address"/> <field name="Date and Time"/> <field name="courier"/> <field type="Customer"/> </tree> </field> </record>

Avatar
Discard
Best Answer

I just did it for v13 replacing Create button with my custom button, you can edit to replace import, export, delete or any button you wish.

You need to extend the ListView XML, create the JS action handler and the python method:
static/src/xml

<?xml version="1.0" encoding="UTF-8"?>
 <template xml:space="preserve">
 <t t-extend="ListView.buttons">
 <t t-jquery="button.o_list_button_add" t-operation="replace">
 <button t-if="widget.modelName == 'my.model'" class="btn btn-primary o_list_tender_button_create" type="button">Custom Button</button>
 <button t-if="widget.modelName != 'my.model'" class="btn btn-primary o_list_button_add" type="button">Create</button>
 </t>
 </t>
 </template>

static/src/js

odoo.define('invoice.action_button', function (require) {
"use strict";
/**
 * Button 'Create' is replaced by Custom Button 
**/

var core = require('web.core');
var ListController = require('web.ListController');
ListController.include({
   renderButtons: function($node) {
   this._super.apply(this, arguments);
       if (this.$buttons) {
         this.$buttons.find('.o_list_tender_button_create').click(this.proxy('action_def'));
       }
    },
     
    //--------------------------------------------------------------------------
    // Define Handler for new Custom Button
    //--------------------------------------------------------------------------

    /**
     * @private
     * @param {MouseEvent} event
     */
    action_def: function (e) {
        var self = this;
        var active_id = this.model.get(this.handle).getContext()['active_ids'];
        var model_name = this.model.get(this.handle).getContext()['active_model'];
            this._rpc({
                    model: 'my.model',
                    method: 'js_python_method',
                    args: ["", model_name, active_id],
                }).then(function (result) {
                    self.do_action(result);
                });
   },
});
});

models

    def js_python_method(self, model_name, active_id):        
        """ Method called from JS custom button ""
        .... your python logic here! .....       

 

Avatar
Discard

Hi Mayte, I have been trying to do that and just print a Hello World, but I'm unable... any sugestion wellcome, buton appears but i cannot execute python funtion.

Tomas, check the console for JS errors.

Best Answer

How this can be do in Odoo 12 Becuz <T t if = "widget.model == 'your.model'"> is not working in v12.

Avatar
Discard
Best Answer

Hi 

This is working in ODOO 9

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

<T t-jquery = "button.oe_list_add" t-operation = "after">

<T t if = "widget.model == 'your.model'">

<Button class = "oe_button oe_list_add_planing_daily oe_highlight"

type = "button"> Create Planing Daily </ button>

<Button class = "oe_button oe_list_view_current_session oe_highlight"

type = "button"> Current Session </ button>

</ T>

</ T>

</ T>

i got it from https://www.odoo.com/forum/help-1/question/how-can-create-a-new-button-in-the-header-of-the-tree-view-after-the-create-button-or-import-104997




Avatar
Discard
Best Answer

@Ajit Padhi

On Odoo 12:

<t t-if="widget.modelName == 'stock.quant'">

Avatar
Discard