2

I am trying to include my custom javascript in my module but the js file is not getting loaded.

Below is my code:

js:

openerp.hr_timesheet_extended = function (instance) {

    var QWeb = instance.web.qweb,
        _t  = instance.web._t,
        _lt = instance.web._lt;

    instance.hr_attendance.AttendanceSlider.include({
    // override methods
    });
};

xml:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <template id="assets_backend" name="hr_attendance assets" inherit_id="web.assets_backend">
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/my_module/static/src/js/attendance.js"></script>
            </xpath>
        </template>
    </data>
</openerp>

What am I doing wrong here?

1
  • Did you add the xml file to the __openerp__.py? Try writing the name of your module as the xml file name (your_module_name.xml) and replace the name of the template to name="your_module_name assets". Do you get any error in the console of your browser? Write and example of a overriden method and try writing some console.log() to check if the file is executed Commented Aug 14, 2015 at 10:25

1 Answer 1

3

Whenever you inherit any template and append your files to that template,

<xpath expr="." position="inside">

your files will be appended first then the other existing files, so whenever it will load it's won't found any existing files, this happens only in web xml inheritance.

Solution:

Add your file after all the base file.

<xpath expr="//script[@src='/pos_restaurant/static/src/js/notes.js']" position="after">

Give complete path in expr rather than "." only.

Attention:

Make sure the js/css source file are under hierarchy structure "static/src/js/" or "static/src/css/" in the root of the module folder.

Sign up to request clarification or add additional context in comments.

8 Comments

But where exactly should my complete path start? from the position of current xml file or some specific position?
Complete path should start from addons folders path, I mean "/" is addons folder path, root = addons path which you have configured, so pos_restaurant is the module in addons, similarly you can set path for your custom module.
But if my src position is outside the addons path, can i use ../ to go back? I have tried but still 404... since my customized module is outside addons folder...
For example, my js/css folder is called A, A folder is at the same level with folder openerp, could you tell me what should my "expr" be here? Cause I may have to go back from my addons-path but i don't know how T_T
It should be within the module and module should be in addon path.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.