This question has been flagged
2 Replies
9879 Views

Hello, I am trying to add a new button above the product tree view, right after the create and import buttons. I tried following these steps: https://www.odoo.com/pt_BR/forum/help-1/question/add-custom-button-to-list-view-header-90255, but wasn't successful. 

I have no clue of how I will actually call the action I want, but so far I can't even get the button to show up. can someone point out what I am missing? What I have so far is a view with the following lines:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="vtex_connector.raizs" name="Template Name">
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_import" t-operation="after">
<button t-if="widget.modelName == 'product.template'" type="button" class="btn btn-primary oe_new_button" accesskey="f">
Upload
</button>
</t>
</t>
</template>
</data>
</odoo>
Avatar
Discard
Best Answer

button.xml

<templates>
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_add" t-operation="after" >
<button type="button" t-if='widget.modelName == "m.dha.sig"'
class="btn btn-primary btn-sm o_list_button_upload">Upload
</button>
</t>
</t>
</templates>

__manifest__.py
'qweb':[
'static/src/xml/button.xml',
],
Avatar
Discard
Best Answer

Hi 

For ListView:

<template xml:space="preserve">
    <t t-extend="ListView.buttons">
<t t-jquery="button.oe_list_add" t-operation="after">
<!-- Your button here -->
</t>
</t>
</template>

For FormView:

<t t-extend="FormView.buttons">
    <t t-jquery="button.oe_form_button_create" t-operation="after">
<button type="button">My button</button>
</t>
</t>
Avatar
Discard

button.oe_form_button_create its not working in odoo15

xml:
<t t-name="library_management_system.my_test_button">
<button type="button" class="btn btn-secondary o_button_my_test">
My Test Button
</button>
</t>

<t t-extend="FormView.buttons" t-name="MyTestButtonFormView.buttons">
<t t-jquery="button.o_form_button_create" t-operation="after">
<t t-call="library_management_system.my_test_button"/>
</t>
</t>

.js code

odoo.define('library.rent.book.tree', function (require) {
"use strict";

var FormController = require('web.FormController');
var FormView = require('web.FormView');

var viewRegistry = require('web.view_registry');

function renderMyTestButton() {
if (this.$buttons) {
var self = this;
// var lead_type = self.initialState.getContext()['default_type'];
this.$buttons.on('click', '.o_button_my_test', function () {
self.do_action({
name: 'My Test Button',
type: 'ir.actions.act_window',
res_model: 'library.books',
target: 'new',
views: [[false, 'form']],
// context: {'is_modal': true, 'default_lead_type': lead_type},
});
});
}
}

var MyTestButtonFormController = FormController.extend({
willStart: function() {
console.log('-=-=-=-=-',this)
var self = this;
var ready = this.getSession().user_has_group('base.group_erp_manager')
.then(function (is_erp_manager) {
if (is_erp_manager) {
self.buttons_template = 'MyTestButtonFormView.buttons';
}
});
return Promise.all([this._super.apply(this, arguments), ready]);
},
renderButtons: function () {
this._super.apply(this, arguments);
renderMyTestButton.apply(this, arguments);
}
});

var MyTestButtonFormView = FormView.extend({
config: _.extend({}, FormView.prototype.config, {
Controller: MyTestButtonFormController,
}),
});

viewRegistry.add('library_rent_book_form_button', MyTestButtonFormView);

});

The issue is button not showing in form view header