Skip to Content
Menu
This question has been flagged
1 Reply
12290 Views

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.

Avatar
Discard
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'],


Avatar
Discard

Neat Explanation.

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)

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);

}

},

});

});

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

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:


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.

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

Related Posts Replies Views Activity
1
Oct 19
6667
1
Oct 19
2730
2
Oct 19
7957
2
Jun 22
2111
0
Jul 17
3870