Odoo Help

2

0
1 Answer
2
Fréjus Arnaud AKA Côte d'Ivoire
10/14/19, 5:49 PM

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


5 Comments
Hilar AK Oman
10/15/19, 1:32 AM

Neat Explanation.

Odoo Programming Hub, gain charlie Philippines
10/15/19, 11:12 AM

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)

Fréjus Arnaud AKA Côte d'Ivoire
10/15/19, 4:25 PM

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

}

},

});

});

Odoo Programming Hub, gain charlie Philippines
10/16/19, 11:14 AM

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

Odoo Programming Hub, gain charlie Philippines
10/16/19, 11:44 AM
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.

Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now