← Back to team overview

openerp-dev team mailing list archive

OpenERP server available as a Python module

 

Hi,

Now that the release of the 6.0 version of OpenERP is done, we are happy
to have the opportunity to tackle something we wanted to do for some
time: make the server code available as an 'openerp' python module.

The necessary changes should be done in 'trunk' by the time you receive
this message. To retain backward compatibility, all the available
symbols under openerp will still be available without the 'openerp.'
prefix. All current addons should work unchanged but you can start to
use the new 'openerp.' hierarchy now.

This move is just a start and we want to bring more improvements. In
particular, we plan to reorganize the content of some modules,
especially 'openerp.tools'.

Note that now the bin/openerp-server.py script is moved at the root of
the project. A wrapper is available in bin/ if you need it.

To demonstrate the use of the openerp module, here is a little script.
You can try it without any OpenERP server running and it will set any
non-'active' user to 'active' in the 'test' database. We plan to provide
a better API in the future. The appropriate use of try/except/finally
should be added to any real code using cr.

    import openerp
    openerp.tools.config['addons_path'] = '/home/openerp/repo/addons/'
    db, pool = openerp.pooler.get_db_and_pool('test')
    cr = db.cursor()

    res_users = pool.get('res.users')
    ids = res_users.search(cr, 1, [('active', '=', False)])

    for record in res_users.browse(cr, 1, ids):
        print record.name
        res_users.write(cr, 1, [record.id], {'active': True})

    cr.commit()
    cr.close()

Any feedback/comments welcome!

Thu
(On behalf of the R&D team)