This question has been flagged

I am trying to extend a Web JS module to override the function set_title_part(). The module I developed works perfectly for OpenERP 7 but does not work for Odoo 8.

Module Name: generic_web_customization

_openerp_.py

{
    'name': 'Generic Web Customization',
    'version': '1.0',
    'category': 'Web',
    'summary': 'Apply generic customizations',
    'description': """ Apply generic customizations  """,
    'author': 'Shawn',
    'website': 'http://www.google.com',
    'depends': ['base','web'],
    'demo': [],
    'installable': True,
    'application': True,
    'auto_install': False,
}

 

/static/src/js/custom_title.js

openerp.generic_web_customization = function(instance)
{
    instance.web.WebClient.include(
    {
        set_title_part: function(part, title) {
            var tmp = _.clone(this.get("title_part"));
            tmp[part] = title;
            this.set("title_part", tmp);

           console.log("extended");
        },
    });
};

__init__.py

// Empty class, as there are no python files to be included

 

I have followed the Odoo tutorial exactly as described, but the JS file does not get invoked. I can't progress any further as a result of this issue. Would appreciate any input on this. Thanks !

 

 

Avatar
Discard
Author

Looking through some of the default modules, it seems that they have explicitly called the .js files from an xml file with template inheriting "web.assets_backend". Is this the way to invoke .js files in Odoo 8 ? The Odoo docs made it seem like browsers automatically look for a static/src folder to execute .js and .css files . Why is the procedure made so horribly complex now?

Best Answer

Hello Shawn,

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>

 

Hope this will help you.

Regards,

Anil.

 

Avatar
Discard
Author

Thank you Anil! Yes, I had noticed this in the default modules too. I thought it would be possible to directly call the .js file by including it in the manifest file in some way, like in OpenERP 7. I guess referencing it from XML is the only way then. Thanks !

Best Answer

It seems this doesn't work on login form or before login, I even started odoo with --load web,mymodule adding .js in assets and they are not loaded.

For example how to load .js, in the web/database/manager form?

Avatar
Discard