(Migrated) Odoo ping connection

(This message has been automatically imported from the retired mailing list)

Hello,

can anyone familiar with Odoo help me out with this one?

I’m moving the Odoo connector from zato-labs over to the core and one of
the things the connector should have is the ability to ping the already
established connections, just like outgoing HTTP or SQL connections in
Zato can be pinged today.

I’m trying to find a model that is guaranteed to exist in Odoo no matter
the installation and I think the code below should do the trick:

“”"
import openerplib

connection = openerplib.get_connection(hostname=‘localhost’,
database=‘odoo’, login=‘admin’, password=‘admin’)
user_model = connection.get_model(‘res.users’)
ids = user_model.search([(‘login’, ‘=’, ‘admin’)])
user_info = user_model.read(ids[0], [‘login’])

print(user_info[‘login’])
"""

Obviously, ‘admin/admin’ is what users provide in the GUI.

And - given a username and password, if they are correct then we should
have access to res.users as otherwise we would not have logged in at
all. Next, we should be able to search for our own login details in
res.users, again, because we have just been able to make use of that model.

Do you think this is guaranteed to work?

thanks,

You should be ok with that but a few tweak can be made. A search over
res.user with the same login as the authenticated one should return the id
of the current user but that id could be obtained from connection.user_id
after the login has been issued, something like this:

“”"
import openerplib

connection = openerplib.get_connection(hostname=‘localhost’,
database=‘odoo’, login=‘admin’, password=‘admin’)
user_model = connection.get_model(‘res.users’)
connection.check_login()
user_info = user_model.read(connection.user_id, [‘login’])

print(user_info[‘login’])
"""
this makes one less call to openerp/odoo server and you could do what you
want in the first place, or you just simple could issue connection.
get_user_context()

On Wed, Oct 22, 2014 at 8:29 AM, Dariusz Suchojad dsuch@zato.io wrote:

Hello,

can anyone familiar with Odoo help me out with this one?

I’m moving the Odoo connector from zato-labs over to the core and one of
the things the connector should have is the ability to ping the already
established connections, just like outgoing HTTP or SQL connections in
Zato can be pinged today.

I’m trying to find a model that is guaranteed to exist in Odoo no matter
the installation and I think the code below should do the trick:

“”"
import openerplib

connection = openerplib.get_connection(hostname=‘localhost’,
database=‘odoo’, login=‘admin’, password=‘admin’)
user_model = connection.get_model(‘res.users’)
ids = user_model.search([(‘login’, ‘=’, ‘admin’)])
user_info = user_model.read(ids[0], [‘login’])

print(user_info[‘login’])
"""

Obviously, ‘admin/admin’ is what users provide in the GUI.

And - given a username and password, if they are correct then we should
have access to res.users as otherwise we would not have logged in at
all. Next, we should be able to search for our own login details in
res.users, again, because we have just been able to make use of that model.

Do you think this is guaranteed to work?

thanks,


Dariusz Suchojad

https://zato.io
ESB, SOA, REST, APIs and cloud integrations in Python

On 22/10/14 23:53, Axel Mendoza Pupo wrote:

You should be ok with that but a few tweak can be made. A search over
res.user with the same login as the authenticated one should return the
id of the current user but that id could be obtained from
connection.user_id after the login has been issued, something like this:

[…]

Thanks Axel!