Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Simple and powerfull tools for programming in Odoo framework (f.e shell, reference to models in stand-alone applications, Mediator pattern for intermodel communications)

Project description

This package implements tools which help you to access database using Odoo models’ mechanizm. Use Odoo Gateway and you will be able to

  • Run models’ methods in shell. Usefull when you need to fix some database data or test you code.
  • Create stand-alone scripts which can refer to Odoo models and call their methods.




To use Odoo Gateway properly you need only Odoo library of 7 or 8 versions.


You can use pip:

$ pip install odoo_gateway


Shell can be launched with:

$ odoosh [params]

Parameters are the same as openerp server’s ones. You can list then any time, just type:

$ odoosh --help

Ok, lets do it right now!:

$ odoosh -c config_file.conf -d database1

In [1]:

Nice! Odoo shell is launched now. Following objects are already in namespace:

  • cr - Odoo wrapper for psycopg’s cursor:

    In [2]: cr
    <openerp.sql_db.Cursor at 0x3450d50>
    In [3]: cr.execute("select id, name from sale_order limit 1")
    In [4]: cr.fetchall()
    [(600094, u'SALE-123456')]``
  • conn - Psycopg’s connection to database:

    In [5]: conn
    <connection object at 0x3485f60; dsn: 'host=localhost port=5432 user=odoo password=xxxx dbname=database1', closed: 0>
    In [6]: conn.rollback()
  • rr - Psycopg’s cursor

  • uid - Id of Odoo superuser

  • conf - Instance of that contains parsed Odoo parameters:

    In [7]: conf
    < at 0x210bbd0>
    In [8]: conf['db_name']
    In [9]: conf['db_host']
  • models - Adapter for Odoo models’ list.:

    In [10]: models.sale_order  # get reference for model
    sale.order sale.order()
    In [11]: type(models.sale_order)
    In [12]: """Now we are free to apply API and user defined methods of model."""
    In [13]: sale1 =[('name','=', 'sale-111111')])
    In [14]: sale-111111
    In [15]: sale2 = models['sale.order'].search([('name','=', 'sale-111112')])
    In [16]: sale-111112

    There are two ways to refer to Odoo model.

  • You can use model’s name name.of.model and get reference with models[name.of.model]. See line 15 of example above.
  • Or you can replace ‘.’ with ‘_’ and type models.name_of_model. The result will be the same as in previous point. See lines 10-14.
  • session - Instance of odoo_gateway.session.Session

Stand-alone scripts

There are problems which require using openerp API outside the openerp server, in another independent process. For example imagine that you have a Shop. Done? Ok. There is a python application APP. APP is a messenger and uses the system of queues. Customers send messages in which they describe what products they want to buy. APP gets messages from queues, parses them and create sale orders in database.

I belive that APP does not need for openerp server to be launched. No, sir!

All you need is instance of odoo_gateway.session.Session, which is initiated with odoo server’ command parameters.:

from odoo_gateway import Session
session = Session(['-c', 'config.conf', '-d', 'testdb'])

As you get session object you can get anything you may dream about.:

models = session.models
cr =
conn = session.conn
uid = session.uid
rr = session.rr
conf = session.conf

# The power is yours now

def create_sale(**params):



Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for odoo_gateway, version 0.131
Filename, size File type Python version Upload date Hashes
Filename, size odoo_gateway-0.131.tar.gz (5.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page