-
Notifications
You must be signed in to change notification settings - Fork 59
Connections and Sessions
Ooor communicates with Odoo using JSON over HTTP(S) requests such a connection is bound to:
- an Odoo server URL
- a database
- a user credential (login/password)
However, the same "Odoo connection" can have multiples sessions. This happens if the same Odoo users connects through different devices. A more useful case is when a website is browsed by unauthenticated users all possibly sharing the same public portal Odoo user but having a different web cookie. For instance each anonymous user can have their own shopping cart until they eventually log in as specific Odoo user later in the sale process. So an ooor session delegates many responsibilities to its Odoo connection object but each session is however identified with a unique cookie (the Odoo session_id) which is possibly bound to a unique Rails cookie and a unique Odoo web session (the Odoo web cookie). None of the Python clients around have such an advanced design and ooor really unleash the power of the web for Odoo.
This is where we introduced the concept of Session. As you can see in the code, a session is just a wrapper around a connection, using Ruby "delegator" framework to delegate its job to the connection and having just some session data that is usually mapped to web HTTP session of the user, that is for instance the cookie session in Rails.
You have probably seen that Ooor creates proxies for Odoo business objects, like ProductProduct ResCountry, SaleOrder...
But these proxies are "global" proxies that you can use only if you don't care about web sessions. For instance in some console administration script or in some TerminatOOOR data importation script, you don't care about web sessions for different users and this is perfectly fine to use these proxies.
Now, in a web application, for instance a Rails application, you probably want that a web users seamlessly map to a Odoo user, in the proper database. And even in the case of anonymous users you may want that Odoo treats them as different unique sessions of the same portal Odoo user.
To achieve that, you should not use these global proxies. Instead, you should create a proper Session for each web user and use the proxies attached to these sessions. Fortunately Ooor makes this easy.