简体   繁体   中英

How to add button after create/import button on Odoo 11

I write button.xml and qweb in manifest .py but it not worked.

button.xml (static/src/xml/button.xml)

<?xml version="1.0" encoding="UTF-8"?>
<templates>
    <t t-extend="ListView.buttons">
        <t t-jquery="button.o_list_button_add" t-operation="after">
            <button name="xxx" type="button" t-if='widget.modelName == "billing.info.functions"'
                    class="btn btn-sm btn-default o_import_button o_import_import">Upload
            </button>
        </t>
    </t>
</templates>

manifest .py

'qweb': [
        "static/src/xml/button.xml"
    ],

Pairat Atichart

XML File Code to add the button :

Add the custom class to manage the visibility of the button [ oe_list_button_custom_class ]

<t t-extend="ListView.buttons">
    <t t-jquery="button.o_list_button_add" t-operation="after">
        <button type="button" class="btn btn-sm btn-default oe_list_button_custom_class">Upload</button>
    </t>
</t>

JS Code to handle visibility and other operation:

var ListController = require('web.ListController');
ListController.include({
    renderButtons: function($node) {
        var self = this;
        this._super.apply(this, arguments);
        var button = $(this.$buttons.find('.oe_list_button_custom_class'));
        button.css("display", "none");
        if (this.modelName == "billing.info.functions") {
            button.css("display", 'inline');
        }
    },
});
Try to extend ImportView insted of ListView as like below:

<templates>
    <t t-extend="ImportView.import_button">
        <t t-jquery="button.o_button_import" t-operation="after" >
            <button type="button" class="btn btn-secondary o_import_import">
                <span><i class="fa fa-file-excel-o"></i></span>
                Load File
            </button>
        </t>
    </t>
</templates>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM