Odoo Help

Welcome!

This community 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.

0

Extended Web JS module not working

By
Shawn Varghese
on 1/18/15, 12:55 AM 2,694 views

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 !

 

 

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?

Shawn Varghese
on 1/18/15, 1:00 AM
3

Anil R. Kesariya

--Anil R. Kesariya--
4321
| 6 5 8
Gandhinagar, India
--Anil R. Kesariya--
ERP Consultant

Key Skill
-
Technical & Functional Expert
Anil R. Kesariya
On 1/18/15, 1:52 AM

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.

 

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 !

Shawn Varghese
on 1/18/15, 2:24 AM
0
Carlos Almeida
On 11/3/15, 2:20 AM

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?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/18/15, 12:55 AM
Seen: 2694 times
Last updated: 11/3/15, 2:20 AM