This question has been flagged
4 Replies
9926 Views

Hi ! I'm on Odoo (v8).

I try to add some Javascript in my Odoo website.

Here's a sample of JS:

$(document).ready(function () {
    var foobar = new openerp.Model("foo.bar");
    var ids = foobar.call("get_dummy_ids", 1);
});

Here's where I include it:

<template id="my_module.assets_frontend" name="Website assets">
    <script type="text/javascript" src="/my_module/static/src/js/my_js.js"></script>
</template>

And here's the error:

Uncaught Error: Not session specified

Anyone have messed up with this issue ?


Update:

I tried this js code:

new openerp.Model(new openerp.Session(), 'res.users').call('search')

But it says:

"Server application error" Object { message: "Odoo Session Expired", code: 100, data: Object }
declare/genericJsonRpc/result<() ceba8ad:1120
.Deferred/promise.then/</</<() ceba8ad:249
jQuery.Callbacks/fire() ceba8ad:243
jQuery.Callbacks/self.fireWith() ceba8ad:248
done() ceba8ad:682
.send/callback()

Since I try to call it when no user is logged in, I kind of get it. But then, is there a way to query the model when no user is logged in ?

Avatar
Discard
Author Best Answer

Thanks to Neda Zilinskas, which pointed me in the right direction.

With a visitor's session (unregistered user), you can't call the openerp.Model functions it seems.

However, I was able to successfully call a controller function, via it's route ('/something'), like that:

var s = new openerp.Session();
s.rpc('/some/route', {
foo: bar,
}).then(function(result) {
console.log(result);
});


Avatar
Discard
Best Answer

Hi PY,

Looks like an old post, but I will still post an answer for the record.

Before creating a model you need to create a communication with the server session and pass a session to the model constructor as following.

 $(document).ready(function () {
    var session = new openerp.Session();
    var foobar = new openerp.Model(session, "foo.bar");
    var ids = foobar.call("get_dummy_ids", 1);
});


Avatar
Discard
Author

Old question, but I needed this answer now ^^ I will try that, thanks !

Author

Updated my question