Odoo loading javascript files in version 8?

你。 提交于 2019-12-06 09:57:24

问题


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?


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/29166447/odoo-loading-javascript-files-in-version-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!