sss
sss

Reputation: 107

JavaScript in odoo 12

I want to create a new js file in odoo.

This file is work on the button which is created in a tree view. This tree view is available in an XML file. For this, I have created one js file in the static folder. But I don't know how this button call function of the js file. What is web.core? If I want to access models in odoo how to access this model?

Upvotes: 0

Views: 719

Answers (1)

Jack Sparrow
Jack Sparrow

Reputation: 666

You can call a function by defining in events in a js file. For Example, here I am accessing chatterbox

odoo.define('yourmodule.js script', function (require) {
"use strict";

var attchment_box = require('mail.AttachmentBox');
var core = require('web.core');

var QWeb = core.qweb;

attchment_box.include({
events: _.extend({}, attchment_box.prototype.events, {
    "click .your button class or # button id": "your method name",

}),
init: function () {

    this._super.apply(this, arguments);

},
start: function() {

    this._super.apply(this, arguments);
},


your method: function (ev) {
    //Your button code
 },
});

});

Like this, you can extend tree view and add button code in the js file.

Upvotes: 2

Related Questions