Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

How to add Button on treeview header and to call a wizard from Odoo 12?

Subscribe

Get notified when there's activity on this post

This question has been flagged
treeviewbuttonsodoo12
1 Reply
14133 Views
Avatar
gain charlie

Hi Odoo Experts,

I want to add a new button place on treeview header in odoo 12 and call a wizard to do something.

I have research and found some blogs but its on older version.

I did try it but it fail to make it work.

Thank you for your time and help in advance.

2
Avatar
Discard
Avatar
SLIFE AFRICA
Best Answer

STEP 1: INHERIT THE TREE VIEW QWEB TEMPLATE

Define a xml file : static/src/xml/template.xml
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_add" t-operation="after">
<button t-if='widget' type="button" class="btn btn-secondary o_button_to_call_wizard">
    Import
   </button>
</t>
</t>


STEP 2: INHERIT THE LIST CONTROLLER JS

Define a js file : static/src/js/list_controller.js
odoo.define('your_module_folder.JsToCallWizard', function (require) {
"use strict";

var ListController = require('web.ListController');

var JsTocallWizard = ListController.include({
renderButtons: function($node){
this._super.apply(this, arguments);
if (this.$buttons) {
this.$buttons.on('click', '.o_button_to_call_wizard', this.action_to_call_wizard.bind(this));
this.$buttons.appendTo($node);
}
},
action_to_call_wzard: function(event) {
event.preventDefault();
var self = this;
self.do_action({
name: "Open a wizard",
type: 'ir.actions.act_window',
res_model: 'my.wizard.model.name',
view_mode: 'form',
view_type: 'form',
views: [[false, 'form']],
target: 'new',
});

},
});
});

STEP 3 : ADD YOUR JS FILE IN ASSETS BACKEND

XML File : views/assets_backend.xml
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<template id="assets_backend" inherit_id="web.assets_backend" name="Backend Assets">
<xpath expr="//script[last()]" position="after">
<script src="/your_module_folder/static/src/js/list_controller.js"></script>
</xpath>
</template>
</odoo>

STEP 3: DECLARE YOUR FILES IN MANIFEST

'data': ['views/assets_backend.xml'],
'qweb': ['static/src/xml/template.xml'],


2
Avatar
Discard
Hilar Andikkadavath

Neat Explanation.

gain charlie
Author

Hi, Frejus,

I have created the file above and replace "your_module_folder" in both js file.

I have added the manifest file param in both 'data' and 'qweb ' .

Question, is 'qweb' applicable to Odoo 12?( cant see it in manifest odoo 12 documentation.)

When i run it i got the following error( am not familiar with js):

Uncaught TypeError: Cannot read property 'bind' of undefined

http://localhost:8069/web/content/491-e52e898/web.assets_backend.js:3194

Traceback:

TypeError: Cannot read property 'bind' of undefined

at Class.renderButtons (http://localhost:8069/web/content/491-e52e898/web.assets_backend.js:3194:330)

at Class.renderButtons (http://localhost:8069/web/content/457-f2407d2/web.assets_common.js:3541:371)

at Class._renderControlPanelElements (http://localhost:8069/web/content/491-e52e898/web.assets_backend.js:1290:175)

at Class.start (http://localhost:8069/web/content/491-e52e898/web.assets_backend.js:1282:1427)

at Class.prototype.(anonymous function) [as start] (http://localhost:8069/web/content/457-f2407d2/web.assets_common.js:3538:488)

at Class.start (http://localhost:8069/web/content/491-e52e898/web.assets_backend.js:1541:1042)

at Class.prototype.(anonymous function) [as start] (http://localhost:8069/web/content/457-f2407d2/web.assets_common.js:3538:488)

at http://localhost:8069/web/content/457-f2407d2/web.assets_common.js:3683:52

at http://localhost:8069/web/content/457-f2407d2/web.assets_common.js:802:681

at fire (http://localhost:8069/web/content/457-f2407d2/web.assets_common.js:796:299)

SLIFE AFRICA

You can try this code :

odoo.define('your_module_folder.JsToCallWizard', function (require) {

"use strict";

var ListController = require('web.ListController');

var JsTocallWizard = ListController.include({

renderButtons: function($node){

this._super.apply(this, arguments);

if (this.$buttons) {

this.$buttons.on('click', '.o_button_to_call_wizard', function () {

var self = this;

self.do_action({

name: "Open a wizard",

type: 'ir.actions.act_window',

res_model: 'my.wizard.model.name',

view_mode: 'form',

view_type: 'form',

views: [[false, 'form']],

target: 'new',

});

});

this.$buttons.appendTo($node);

}

},

});

});

gain charlie
Author

I have copied everything on hr_clock_import/static/src/js/list_controller.js the above code,

except replaced "your_module_folder" to hr_clock_import.

Result : Error gone.

But it does not display the button on the tree view header. i.e. after CREATE or IMPORT button

Am trying to add a new button from ATTENDANCE treeview called DOWNLOAD

OdooBot
Hi Frejus,

I have copied everything on hr_clock_import/static/src/js/list_controller.js the above code,

except replaced "your_module_folder" to hr_clock_import.

Result : Error gone.

But it does not display the button on the tree view header. i.e. after CREATE or IMPORT button

Am trying to add a new button from ATTENDANCE treeview called DOWNLOAD


I have attached my code below for your analysis.
Thank your for your time.
God Bless!

Gain Charlie
Odoo User
On Wednesday, 16 October 2019, 4:26:31 am GMT+8, Fréjus Arnaud AKA <frejusarnaud@gmail.com> wrote:


View Forum Post Odoo S.A.

You can try this code :

odoo.define('your_module_folder.JsToCallWizard', function (require) {

"use strict";

var ListController = require('web.ListController');

var JsTocallWizard = ListController.include({

renderButtons: function($node){

this._super.apply(this, arguments);

if (this.$buttons) {

this.$buttons.on('click', '.o_button_to_call_wizard', function () {

var self = this;

self.do_action({

name: "Open a wizard",

type: 'ir.actions.act_window',

res_model: 'my.wizard.model.name',

view_mode: 'form',

view_type: 'form',

views: [[false, 'form']],

target: 'new',

});

});

this.$buttons.appendTo($node);

}

},

});

});

Sent by Odoo S.A. using Odoo.

Tri Nanda

I got this error:
Uncaught TypeError: self.do_action is not a function

when using the last code @gain charlie
is there any solustions @gain charlie and @Fréjus Arnaud AKA and anyone on this forum?

Thanks,
Tri

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How to add buttons in tree view header and run a function in Odoo 12?
treeview buttons odoo12
Avatar
Avatar
1
Oct 19
7720
In Odoo 12, How to create a new button alongside CREATE button of a treeview and call a wizard
wizard treeview buttons odoo12
Avatar
Avatar
1
Oct 19
3814
Odoo 12, how to add a button to treeview header and call the existing wizard? Solved
wizard treeview buttons odoo12
Avatar
Avatar
Avatar
2
Oct 19
9319
add one button in treeview to sync many records from another app API Solved
treeview buttons
Avatar
Avatar
2
Jun 22
3469
input type text field and my button instead default buttons in treeview
treeview buttons
Avatar
0
Jul 17
4942
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now