Coder Social home page Coder Social logo

osiell / oerplib Goto Github PK

View Code? Open in Web Editor NEW
21.0 7.0 20.0 4.08 MB

OERPLib is a Python RPC library which aims to provide an easy way to remotely pilot and manage an OpenERP server.

License: GNU Lesser General Public License v3.0

Python 95.32% Makefile 1.87% Shell 1.67% CSS 1.13%

oerplib's Introduction

OERPLib

Downloads Latest Version License

OERPLib is a Python module providing an easy way to pilot your OpenERP and Odoo servers through RPC.

Features supported:
  • XML-RPC and (legacy) Net-RPC protocols,
  • access to all methods proposed by a model class (even browse) with an API similar to the server-side API,
  • ability to use named parameters with such methods (server >= 6.1),
  • user context automatically sent (server >= 6.1) providing support for internationalization,
  • browse records,
  • execute workflows,
  • manage databases,
  • reports downloading,
  • inspection capabilities (graphical output of relations between models and dependencies between modules, list on_change methods from model views, ...).

How does it work? See below:

import oerplib

# Prepare the connection to the server
oerp = oerplib.OERP('localhost', protocol='xmlrpc', port=8069)

# Check available databases
print(oerp.db.list())

# Login (the object returned is a browsable record)
user = oerp.login('user', 'passwd', 'db_name')
print(user.name)            # name of the user connected
print(user.company_id.name) # the name of its company

# Simple 'raw' query
user_data = oerp.execute('res.users', 'read', [user.id])
print(user_data)

# Use all methods of an OSV class
order_obj = oerp.get('sale.order')
order_ids = order_obj.search([])
for order in order_obj.browse(order_ids):
    print(order.name)
    products = [line.product_id.name for line in order.order_line]
    print(products)

# Update data through a browsable record
user.name = "Brian Jones"
oerp.write_record(user)

See the documentation for more details and features.

Supported OpenERP/Odoo server versions

OERPLib has been tested on OpenERP server v5.0, v6.0, v6.1, v7.0 and Odoo v8.0. It should work on next versions if Odoo keeps a stable API.

Supported Python versions

OERPLib support Python versions 2.6, 2.7.

License

This software is made available under the LGPL v3 license.

Generate the documentation

To generate the documentation, you have to install Sphinx documentation generator:

easy_install -U sphinx

Then, you can use the build_doc option of the setup.py:

python setup.py build_doc

The generated documentation will be in the ./doc/build/html directory.

Bugs or suggestions

Please, feel free to report bugs or suggestions in the Bug Tracker!

Changes in this version

Consult the CHANGELOG.rst file.

oerplib's People

Contributors

danielkauffman avatar etsinko avatar sebalix avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

oerplib's Issues

Port to python3

Currently oerplib only supports python2 but we need python3 support.

Error getting a list of databases

Hi!

First of all, I want to wish you the best this holiday season. I hope you share very nice moments with people who are important to you, and have a wonderful 2015 where you can make all your projects.

That said, I wanted to consult about an error I'm getting when trying to make a list of databases with oerplib. For get the list I am using the following:

oerp = oerplib.OERP('localhost', protocol='xmlrpc', port=8069)

databases = oerp.db.list()

It is not very different from what I saw in the documentation. But this is the exception that occurs after executing that code:

# ./create_odoo_database.py opcionlibre 0 es_AR password
Traceback (most recent call last):
  File "./create_odoo_database.py", line 37, in <module>
    databases = oerp.db.list()
  File "/usr/local/lib/python2.7/dist-packages/oerplib/service/db.py", line 276, in rpc_method
    raise error.RPCError(exc.message, exc.oerp_traceback)
oerplib.error.RPCError: 3

Sorry if this is trivial, but I'm not finding the cause :(

Thanks in advance.

Kind regards,
Daniel

Warning/Errors when using OERPLib with OpenERP 7.0 Branch

Hi!

I'm using OERPLib with OpenERP 7.0 branch since the release of the localization I'm using is not compatible to the 8.0 branch yet. When I create the database for a new instance I see the following errors. Not sure if this is a critical issue since the database seems to be created. Below I copy the log of the instance:

2015-02-21 11:30:40,554 4250 INFO ? openerp: OpenERP version 7.0 
2015-02-21 11:30:40,558 4250 INFO ? openerp: addons paths: /opt/odoo/testcompany/addons 
2015-02-21 11:30:40,560 4250 INFO ? openerp: database hostname: 10.1.0.41 
2015-02-21 11:30:40,560 4250 INFO ? openerp: database port: 5432 
2015-02-21 11:30:40,560 4250 INFO ? openerp: database user: testcompany 
2015-02-21 11:30:41,783 4250 INFO ? openerp.addons.google_docs.google_docs: GData lib version `%s GData-Python/2.0.17` detected 
2015-02-21 11:30:45,769 4250 INFO ? openerp: OpenERP server is running, waiting for connections... 
2015-02-21 11:30:45,771 4250 INFO ? openerp.service.wsgi_server: HTTP service (werkzeug) running on 0.0.0.0:8070 
2015-02-21 11:30:49,666 4250 ERROR ? openerp.netsvc: 2/db 
Traceback (most recent call last): 
  File "/opt/odoo/testcompany/openerp/netsvc.py", line 296, in dispatch_rpc 
    result = ExportService.getService(service_name).dispatch(method, params) 
  File "/opt/odoo/testcompany/openerp/netsvc.py", line 117, in getService 
    return cls._services[name] 
KeyError: '2/db' 
2015-02-21 11:30:49,670 4250 INFO ? werkzeug: 127.0.0.1 - - [21/Feb/2015 11:30:49] "POST /xmlrpc/2/db HTTP/1.1" 200 - 
2015-02-21 11:30:49,676 4250 INFO ? werkzeug: 127.0.0.1 - - [21/Feb/2015 11:30:49] "POST /openerp/xmlrpc/1/db HTTP/1.1" 200 - 
2015-02-21 11:30:49,682 4250 WARNING ? openerp.sql_db: __nonzero__() is deprecated. (It is too expensive to test a connection.) 
2015-02-21 11:30:49,746 4250 ERROR ? openerp.sql_db: Connection to the database failed 
Traceback (most recent call last):
  File "/opt/odoo/testcompany/openerp/sql_db.py", line 442, in borrow 
    result = psycopg2.connect(dsn=dsn, connection_factory=PsycoConnection) 
  File "/usr/lib/python2.7/dist-packages/psycopg2/__init__.py", line 179, in connect 
    connection_factory=connection_factory, async=async) 
OperationalError: FATAL:  no existe la base de datos <<testcompany>> 

2015-02-21 11:30:49,752 4250 INFO ? werkzeug: 127.0.0.1 - - [21/Feb/2015 11:30:49] "POST /openerp/xmlrpc/1/db HTTP/1.1" 200 - 
2015-02-21 11:30:49,761 4250 INFO ? openerp.service.web_services: Create database `testcompany`. 
2015-02-21 11:30:53,964 4250 INFO testcompany openerp.modules.loading: loading 1 modules... 
2015-02-21 11:30:53,983 4250 INFO testcompany openerp.modules.module: module base: creating or updating database tables 
2015-02-21 11:30:58,119 4250 INFO testcompany openerp.osv.orm: Computing parent left and right for table ir_ui_menu... 
2015-02-21 11:31:13,814 4250 INFO testcompany openerp.osv.orm: Computing parent left and right for table res_partner_category... 
2015-02-21 11:31:24,192 4250 INFO testcompany openerp.osv.orm: storing computed values of fields.function 'report_file' 
2015-02-21 11:31:24,198 4250 INFO testcompany openerp.osv.orm: storing computed values of fields.function 'global' 
2015-02-21 11:31:24,201 4250 INFO testcompany openerp.osv.orm: storing computed values of fields.function 'web_icon_hover_data' 
2015-02-21 11:31:24,202 4250 INFO testcompany openerp.osv.orm: storing computed values of fields.function 'web_icon_data' 
2015-02-21 11:31:24,205 4250 INFO testcompany openerp.osv.orm: storing computed values of fields.function 'needaction_enabled' 
2015-02-21 11:31:24,206 4250 INFO testcompany openerp.osv.orm: storing computed values of fields.function 'menus_by_module' 
2015-02-21 11:31:24,508 4250 INFO testcompany openerp.osv.orm: storing computed values of fields.function 'reports_by_module' 
2015-02-21 11:31:24,810 4250 INFO testcompany openerp.osv.orm: storing computed values of fields.function 'views_by_module'
{...}

I also see the following warnings:

2015-02-21 11:32:09,968 4250 WARNING testcompany openerp.osv.orm: Field res.users.user_email is deprecated: Use the email field instead of user_email. This field will be removed with OpenERP 7.1
2015-02-21 11:32:09,974 4250 INFO testcompany werkzeug: 127.0.0.1 - - [21/Feb/2015 11:32:09] "POST /openerp/xmlrpc/1/object HTTP/1.1" 200 - 
2015-02-21 11:32:09,985 4250 INFO testcompany werkzeug: 127.0.0.1 - - [21/Feb/2015 11:32:09] "POST /openerp/xmlrpc/1/object HTTP/1.1" 200 - 
2015-02-21 11:32:10,025 4250 INFO testcompany werkzeug: 127.0.0.1 - - [21/Feb/2015 11:32:10] "POST /openerp/xmlrpc/1/object HTTP/1.1" 200 - 
2015-02-21 11:32:10,086 4250 INFO testcompany werkzeug: 127.0.0.1 - - [21/Feb/2015 11:32:10] "POST /openerp/xmlrpc/1/object HTTP/1.1" 200 -
2015-02-21 11:32:10,115 4250 WARNING testcompany openerp.osv.orm: Field res.users.user_email is deprecated: Use the email field instead of user_email. This field will be removed with OpenERP 7.1.
2015-02-21 11:32:10,123 4250 INFO testcompany werkzeug: 127.0.0.1 - - [21/Feb/2015 11:32:10] "POST /openerp/xmlrpc/1/object HTTP/1.1" 200 - 
2015-02-21 11:32:10,133 4250 INFO testcompany werkzeug: 127.0.0.1 - - [21/Feb/2015 11:32:10] "POST /openerp/xmlrpc/1/object HTTP/1.1" 200 - 
2015-02-21 11:32:10,174 4250 INFO testcompany werkzeug: 127.0.0.1 - - [21/Feb/2015 11:32:10] "POST /openerp/xmlrpc/1/object HTTP/1.1" 200 - 
2015-02-21 11:32:10,296 4250 INFO testcompany werkzeug: 127.0.0.1 - - [21/Feb/2015 11:32:10] "POST /openerp/xmlrpc/1/object HTTP/1.1" 200 - 
2015-02-21 11:32:10,331 4250 WARNING testcompany openerp.osv.orm: Field res.users.user_email is deprecated: Use the email field instead of user_email. This field will be removed with OpenERP 7.1.

It seems the same warning which is repeated three times.

Thanks and best regards.
Daniel

Lazy browse records

Hello Sébastien,

I noticed that upon initialization of BrowseRecord class by calling oerp.browse('model', id) the Oerplib populates the newly created browse record with all fields from the server. This becomes slow for large models (especially when you only need to read one field) and therefore I never use them and instead only do calls to oerp.read() to save time.

What I like about browse records is that they are caching, i.e. by loading it once you can access it many times and it will not re-read data from the server.

I was wondering if there is a way to speed up them. One solution would be to implement a lazy initialization BrowseRecord. Upon creation this record will not do anything, but when a field is accessed the record should check its cache first and if the field is not there it should attempt to fetch it from the server. This should improve the speed considerably.

What do you think?

Egor

Create Database Error

Currently the db.create() has the following error while running against Odoo8:

Python>oerp = oerplib.OERP(server='localhost')
Python>oerp.db.create('super_admin_pass', 'my_db', False, 'fr_FR', 'admin_passwd')

Traceback (most recent call last):
File "", line 1, in
File "build/bdist.linux-x86_64/egg/oerplib/service/db.py", line 276, in rpc_method
oerplib.error.RPCError: (1, 'Traceback (most recent call last):\n File "/opt/python27/lib/python2.7/site-packages/odoo-8.0_edbd0df-py2.7.egg/openerp/service/wsgi_server.py", line 75, in xmlrpc_return\n result = openerp.http.dispatch_rpc(service, method, params)\n File "/opt/python27/lib/python2.7/site-packages/odoo-8.0_edbd0df-py2.7.egg/openerp/http.py", line 108, in dispatch_rpc\n result = dispatch(method, params)\n File "/opt/python27/lib/python2.7/site-packages/odoo-8.0_edbd0df-py2.7.egg/openerp/service/db.py", line 69, in dispatch\n fn = globals()['exp_' + method]\nKeyError: u'exp_create'\n')

Maybe there is some incompatible with the current xmlrpc of Odoo8?

Reset index on BrowseRecordIterator Object

Hello,

I am working actually with this library and I have problems to re-use de BrowseRecordIterator list because I have to reset the index manually.

Maybe you should create a function to reset it...

Compatibility with odoo9

I am getting errors using oerplib with odoo9c. What are the future plans for oerplib in order to support odoo9?

connect to odoo.com saas via https fails

I've tried to connect to odoo.com trial saas without success.
code like this:

oerp = oerplib.OERP('trial1234.odoo.com', protocol='xmlrpc+ssl', port=443)
oerp.db.server_version()
fails for odoo saas.

It looks, like current oerplib version can't work with odoo which avilable ONLY via https:
file - oerplib / oerplib / rpc / init.py

           url = 'http://{server}:{port}{path}'.format(
               server=self.server, port=self.port, path=path)
           try:
               db = service.ServiceXMLRPC(
                   self, 'db', '{url}/{srv}'.format(url=url, srv='db'))
               version = db.server_version()

after changing

url = 'http://{server}:{port}{path}'.format(
to
url = 'https://{server}:{port}{path}'.format(

I see response from odoo saas

oerp = oerplib.OERP('trial1234.odoo.com', protocol='xmlrpc+ssl', port=443)
oerp.db.server_version()
8.0

but still can't login...
service tells me that I'm using wrong user ID or password...

so, is it possible to connect to odoo saas via https, using oerplib?
working sample? suggestions?

Configure user privileges

Hi, Sébastien/etsinko.

After being able to automate the creation of a database with the corresponding administrator, I wonder if it is possible to configure access to "technical features" also automatically after creation (I think this is basic to an administrator user), using oerplib. I think the res_groups table is used for set the privileges, although I didn't see the relation with res_users.

I was also investigating how to create an administrator user with restricted permissions (eg he/her can not install modules). At first I tried it from the web interface for viewing the mechanism to follow and try to replicate it with oerplib, but I could not get it yet. The official documentation on the Odoo official site also was not very useful for me. This is also achieved by configuring the user group?

Thanks again for your time.

Kind regards,
Daniel

How to do the equivalent of pressing the "Transfer" button on a picking via OERPlib?

I have successfully created sales orders and confirmed them via OERPlib. I now have a set of picking operations and want to do the equivalent of pressing the "Transfer" button using a script.

On a sales order I can press "Confirm Sale" via oerp.execute('sale.order', 'action_button_confirm', [sales_order_id]).

But for a picking it appears to be more involved, as the transfer button pulls up a "Products to Move" screen, which allows for adjustment of the products and quantities moved.

I've tried reading the source code, and I am looking at openerp/addons/stock/wizard/stock_transfer_details.py and the do_detailed_transfer() method. But I am reaching the limit of my abilities to understand the Odoo code, beyond ascertaining that the tables stock_transfer_details, stock_transfer_details_items and possibly stock_picking are involved.

Can anyone help with the exact set of database entries I would need to do to created a correct transfer? I have a list of actually transferred products and quantities for the shipment, so the ability to modify the transfer from that proposed would be useful.

Thank you.

Error while creating report on OpenERP 7.0 with multiple workers

Original report : https://bugs.launchpad.net/oerplib/+bug/1371790

Oerplib fails to generate reports when OpenERP 7.0 is running in multi-process mode using 'workers=N'.

Steps to reproduce:

  1. make sure that workers = N (where N > 0) is in openerp-server.conf
  2. Create a new database with demo data enabled
  3. install 'warehouse' and 'sale' modules. These modules will create demo sale order
  4. Use the following snippet to see the error:
import oerplib

oerp = oerplib.OERP(server='localhost', database='test', version='7.0')
oerp.login(user='admin', passwd='test')

print oerp.report('sale.order', 'sale.sale', [8])

The following error is produced:

Traceback (most recent call last):
  File "/home/etsinko/work/PyqtTest/pyqt/widgets/test.py", line 7, in <module>
    print oerp.report('sale.order', 'sale.sale', [8])
  File "/usr/local/lib/python2.7/dist-packages/oerplib/oerp.py", line 317, in report
    report_type, context)
  File "/usr/local/lib/python2.7/dist-packages/oerplib/oerp.py", line 347, in _get_report_data
    raise error.RPCError("Unknown error occurred during the "
oerplib.error.RPCError: Unknown error occurred during the download of the report.
  1. If you set workers = 0 in openerp-server.conf the snippet prints out the name of the temporary file in which report is contained

Set currency related to a country (or how to update data with an on_change method)

Hi!

I'm using oerplib recently. I wrote this question on the Launchpad forum, but I'm not sure if it will remain active after the migration to GitHub. Not sure if this will be the place to discuss my doubts. If it were not so, I would appreciate that indicate me where I could.

I'm trying to automate the configuration data of a company. To set the country I used the following code:

oerp.write('res.partner', [1], {'country_id': country_id})

I get that "country_id" from a direct query in the database (not using oerplib - I don't know if there will be any way to get it directly using oerplib).

This makes the change of the country, but I see no change on the currency based on the change of the country. When setting the country on the web interface, I noticed that the currency is adjusted to the country configured by one. Is there any way to accomplish this same behavior using oerplib?

I also worry that in the same way that this automatic change is not made, there might be other automatic changes that are being lost when to set the country in this way using oerplib.

Thanks in advance.

Kind regards,
Daniel

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.