Andrius
Andrius

Reputation: 21118

Odoo loading javascript files in version 8?

How do you load javascript files in version 8? In version 7, you could simply show the location of js in manifesto file (__openerp__.py) like this:

'js': ['static/src/js/file.js'],

Now it does not work.

For example I created js file in my module with this code:

openerp.calendar_service = function(instance) {
    var _t = instance.web._t,
        _lt = instance.web._lt,
        QWeb = instance.web.qweb;

    instance.calendar_service = {};
    console.log('TEST')
};

But using debugger, I don't see that TEST is printed. If I add such print in some source js files (in other modules), it will print it fine. So how do I make my js files load?

Upvotes: 2

Views: 5582

Answers (2)

Vyas Senthil
Vyas Senthil

Reputation: 153

You have to load your JS file from xml template.

Here you go!

Create one xml file inside views folder and add template record.

your_module>>views>>new_file.xml (This is convention only you can create this record in any xml file)

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="unique_template_id" name="String value" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/your_module_name/static/src/js/your_js_file.js"></script>
            </xpath>
        </template>
    </data>
</openerp>

Upvotes: 4

Hardik Patadia
Hardik Patadia

Reputation: 1999

Check out the example shown in following:

/addons/account/views/account.xml

This will show you how to add the javascript and css files to your module.

Upvotes: 6

Related Questions