Skip to Content
Menu
This question has been flagged
4 Replies
8785 Views

How to Add a New Button like Create Button in the tree view header

Avatar
Discard
Author

Niyas Raphy thanks for your reply 

this video is very helpful but I want to add a button that allows visible, not visible only when I select a record

Best Answer

Hi, 

You can follow this: https://youtu.be/MCEKCBA7zGk

Hope it helps

Avatar
Discard
Best Answer

Hi,

For adding button in tree view in odoo 15, see: https://www.youtube.com/watch?v=R8eG6uOxHKw

Thanks

Avatar
Discard
Best Answer

I understand your question and yes the code is changed in V15.

I tried adding a button on sale order list view and I could achive it using below code.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Avatar
Discard

Js file code:

function ccButton() {
if (this.$buttons) {
var self = this;
this.$buttons.on('click', '.o_button_custom', function () {
self.do_action({
name: 'Generate Leads',
type: 'ir.actions.act_window',
res_model: 'sale.order',
target: 'new',
views: [[false, 'form']],
});
});
}
}

var cListController = ListController.extend({
willStart: function() {
var self = this;
// var ready = self.buttons_template = 'CustListView.buttons';
var ready = this.getSession().user_has_group('sales_team.group_sale_manager')
.then(function (is_sale_manager) {
if (is_sale_manager) {
self.buttons_template = 'CustListView.buttons';
}
});
return Promise.all([this._super.apply(this, arguments), ready]);
},
renderButtons: function () {
this._super.apply(this, arguments);
ccButton.apply(this, arguments);
}
});

var CustListView = ListView.extend({
config: _.extend({}, ListView.prototype.config, {
Controller: cListController,
}),
});

viewRegistry.add('cust_tree', CustListView);

Xml file code :

<field name="name">sale.order.tree</field>
<field name="model">sale.order</field>
<field name="inherit_id" ref="sale.view_quotation_tree_with_onboarding"/>
<field name="mode">primary</field>
<field name="arch" type="xml">
<xpath expr="//tree" position="attributes">
<attribute name="js_class">cust_tree</attribute>
</xpath>
</field>
</record>
</odoo>