Giter VIP home page Giter VIP logo

odoorpc's Introduction

OdooRPC

Latest Version Build Status Supported Python versions License

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

Features supported:
  • access to all data model methods (even browse) with an API similar to the server-side API,
  • use named parameters with model methods,
  • user context automatically sent providing support for internationalization,
  • browse records,
  • execute workflows,
  • manage databases,
  • reports downloading,
  • JSON-RPC protocol (SSL supported),

How does it work? See below:

import odoorpc

# Prepare the connection to the server
odoo = odoorpc.ODOO('localhost', port=8069)

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

# Login
odoo.login('db_name', 'user', 'passwd')

# Current user
user = odoo.env.user
print(user.name)            # name of the user connected
print(user.company_id.name) # the name of its company

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

# Use all methods of a model
if 'sale.order' in odoo.env:
    Order = odoo.env['sale.order']
    order_ids = Order.search([])
    for order in Order.browse(order_ids):
        print(order.name)
        products = [line.product_id.name for line in order.order_line]
        print(products)

# Update data through a record
user.name = "Brian Jones"

See the documentation for more details and features.

Supported Odoo server versions

OdooRPC has been tested on Odoo 8.0, 9.0 and 10.0. It should work on next versions if Odoo keeps a stable API.

Supported Python versions

OdooRPC support Python 2.7, 3.2, 3.3, 3.4, 3.5 and 3.6.

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:

pip install 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 file.

odoorpc's People

Contributors

kvdb avatar naglis avatar rikvermeer avatar sebalix avatar the-compiler avatar thijstriemstra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

odoorpc's Issues

Missing README.rst

Released version 0.1.0 does not include README.rst inside the package.

$ pip install odoorpc
Collecting odoorpc
  Using cached OdooRPC-0.1.0.tar.gz
    No Sphinx module found. You have to install Sphinx to be able to generate the documentation.
    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-build-nzdcBp/odoorpc/setup.py", line 45, in <module>
        long_description=open('README.rst').read(),
    IOError: [Errno 2] No such file or directory: 'README.rst'
    Complete output from command python setup.py egg_info:
    No Sphinx module found. You have to install Sphinx to be able to generate the documentation.

    Traceback (most recent call last):
      File "<string>", line 20, in <module>
      File "/tmp/pip-build-nzdcBp/odoorpc/setup.py", line 45, in <module>
        long_description=open('README.rst').read(),
    IOError: [Errno 2] No such file or directory: 'README.rst'

RPCError ASCII

Hello,

When i try to get some partners from a french database with the code :

connection = odoorpc.ODOO(serveur, port=port,protocol=protocol)
connection.login(base,identifiant,motdepasse)
                  
obj = connection.env['res.partner']
datas = obj.search([])
for data in obj.browse(datas):
   _logger.info(data)

I have this error :

for data in obj.browse(datas):
File "/usr/local/lib/python3.8/site-packages/odoorpc/models.py", line 267, in browse
return cls._browse(cls.env, ids)
File "/usr/local/lib/python3.8/site-packages/odoorpc/models.py", line 233, in _browse
records._init_values()
File "/usr/local/lib/python3.8/site-packages/odoorpc/models.py", line 347, in _init_values
rows = self.class.read(
File "/usr/local/lib/python3.8/site-packages/odoorpc/models.py", line 59, in rpc_method
result = cls._odoo.execute_kw(cls._name, method, args, kwargs)
File "/usr/local/lib/python3.8/site-packages/odoorpc/odoo.py", line 482, in execute_kw
data = self.json(
File "/usr/local/lib/python3.8/site-packages/odoorpc/odoo.py", line 273, in json
raise error.RPCError(
Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/odoo/src/odoo/odoo/http.py", line 640, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/odoo/src/odoo/odoo/http.py", line 316, in _handle_exception
raise exception.with_traceback(None) from new_cause
odoorpc.error.RPCError: ascii

I have indeed some non ascii characters on the partner : é

What can i do ?

Thank you very much :)

use updated URL for wkhtmltopdf downloads

Hello,

wkhtmltopdf has moved the downloads provider from SourceForge to gna.org. As mentioned in the linked message, all earlier downloads have been removed from SourceForge and you are strongly advised to migrate to the new URLs. The following files in your repository will need to be updated:

  • .travis.yml

It is recommended to either subscribe to the mailing list or Twitter feed to receive updates on new releases and further changes.

Thanks,
wkhtmltopdf maintainer

Odoo exception issue with encoding

Hello,

When the user as a language different from English, If Odoo raise a UserError with a message containing special chars the error Message is not available.

Here the trace with the user with french language:

File "/usr/local/lib/python2.7/dist-packages/odoorpc/models.py", line 339, in rpc_method
self._name, method, args, kwargs)
File "/usr/local/lib/python2.7/dist-packages/odoorpc/odoo.py", line 483, in execute_kw
'args': args_to_send})
File "/usr/local/lib/python2.7/dist-packages/odoorpc/odoo.py", line 282, in json
data['error'])
File "/usr/local/lib/python2.7/dist-packages/odoorpc/odoo.py", line 483, in execute_kw
'args': args_to_send})
File "/usr/local/lib/python2.7/dist-packages/odoorpc/odoo.py", line 282, in json
data['error'])
odoorpc.error.RPCError

And here in english
File "/usr/local/lib/python2.7/dist-packages/odoorpc/models.py", line 339, in rpc_method
self._name, method, args, kwargs)
File "/usr/local/lib/python2.7/dist-packages/odoorpc/odoo.py", line 483, in execute_kw
'args': args_to_send})
File "/usr/local/lib/python2.7/dist-packages/odoorpc/odoo.py", line 282, in json
data['error'])
odoorpc.error.RPCError: You cannot cancel an invoice which is partially paid. You need to unreconcile related payment
entries first.

In English we can obtain the error message.

Regards

Nicolas

Error with connecting to some Odoo instances.

I used OdooRPC in the past: Thanks for a great piece of software :)

Recently I wanted to use it to connect to a Odoo 9 that is behind a Nginx reverse proxy.
When I connect to an Odoo running on localhost everything works fine.
(protocol JSONRPC, port 8069)

When I try to connect to the production version (JSONRPC+SSL) I receive the following error:
odoorpc.error.RPCError: request not bound to a database

I'm sure that I used a database that was listed when I executed:

odoo = odoorpc.ODOO('rene-dohmen.odoo.com', protocol='jsonrpc+ssl', port=443)
print(odoo.db.list())

then tried to do the login:
odoo.login('the_db', login='admin', password='password')

To rule out Odoo misconfiguration I wrote a simple tester:
https://gist.github.com/acidjunk/662bad6c216811ca6b4eb119a9b34e8d

That works as expected with the local odoo instance and with the production.

Am I doing something wrong?

Unclosed socket

Just happened to notice this in the Travis log for #16 (with Python 3.3):

test_reduced_timeout (odoorpc.tests.test_timeout.TestTimeout) ... ok
test_session_get (odoorpc.tests.test_session.TestSession) ... /opt/python/3.3.5/lib/python3.3/http/client.py:320: ResourceWarning: unclosed <socket.socket object, fd=3, family=2, type=2049, proto=6>
  line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
ok

Getting records in tutorial

I'm following the tutorial and found that http://pythonhosted.org/OdooRPC/tuto_browse.html#get-records
states:

>>> Purchase = odoo.env['purchase.order']
>>> order = Purchase.browse(1)
>>> order.minimum_planned_date
datetime.date(2014, 10, 8)

but instead of a datetime.date I see:

<function rpc_method at 0x101d86320>

Calling it as a method throws an error:

>>> print(order.minimum_planned_date())
Traceback (most recent call last):
...
odoorpc.error.RPCError: 'purchase.order' object has no attribute 'minimum_planned_date'

Am I missing something or is this field not available anymore? Using OpenERP version 9.0c-20160405.

KeyError when call record method

I use Odoo 9 and create payment via api

Payment = odoo.env['account.payment']
payment_id = Payment.create({...})
Payment.post(payment_id)  # call 'post' method of account_payment model

Last line raises KeyError: 'result' because response is {u'jsonrpc': u'2.0', u'id': 109376199} and has not result key.

Problem running on Ubuntu 15.04/Python 2.7

I try to test Odoorpc 0.2.0 but run into problem while using a standard example
import odoorp
odoo = odoorpc.ODOO(...)

Getting error message:
AttributeError: 'module' object has no attribute 'ODOO'

Any additional dependencies to be aware?

RPCError: exp_dump() takes exactly 2 arguments (1 given)

I just tried running the tests locally by using odoo from Docker and running python -m unittest discover -v.

I got this on the client:

ERROR: test_db_dump (odoorpc.tests.test_db.TestDB)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/florian/proj/odoorpc/odoorpc/tests/test_db.py", line 17, in test_db_dump
    dump = self.odoo.db.dump(self.env['super_pwd'], self.env['db'])
  File "/home/florian/proj/odoorpc/odoorpc/db.py", line 131, in dump
    'args': args})
  File "/home/florian/proj/odoorpc/odoorpc/odoo.py", line 267, in json
    data['error'])
RPCError: exp_dump() takes exactly 2 arguments (1 given)

======================================================================
ERROR: test_db_restore_existing_database (odoorpc.tests.test_db.TestDB)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/florian/proj/odoorpc/odoorpc/tests/test_db.py", line 111, in test_db_restore_existing_database
    dump = self.odoo.db.dump(self.env['super_pwd'], self.env['db'])
  File "/home/florian/proj/odoorpc/odoorpc/db.py", line 131, in dump
    'args': args})
  File "/home/florian/proj/odoorpc/odoorpc/odoo.py", line 267, in json
    data['error'])
RPCError: exp_dump() takes exactly 2 arguments (1 given)

======================================================================
ERROR: test_db_restore_new_database (odoorpc.tests.test_db.TestDB)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/florian/proj/odoorpc/odoorpc/tests/test_db.py", line 103, in test_db_restore_new_database
    dump = self.odoo.db.dump(self.env['super_pwd'], self.env['db'])
  File "/home/florian/proj/odoorpc/odoorpc/db.py", line 131, in dump
    'args': args})
  File "/home/florian/proj/odoorpc/odoorpc/odoo.py", line 267, in json
    data['error'])
RPCError: exp_dump() takes exactly 2 arguments (1 given)

======================================================================
ERROR: test_db_restore_wrong_password (odoorpc.tests.test_db.TestDB)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/florian/proj/odoorpc/odoorpc/tests/test_db.py", line 118, in test_db_restore_wrong_password
    dump = self.odoo.db.dump(self.env['super_pwd'], self.env['db'])
  File "/home/florian/proj/odoorpc/odoorpc/db.py", line 131, in dump
    'args': args})
  File "/home/florian/proj/odoorpc/odoorpc/odoo.py", line 267, in json
    data['error'])
RPCError: exp_dump() takes exactly 2 arguments (1 given)

On the server (not sure if those errors are related):

[...]

2015-11-30 12:24:37,847 1 ERROR odoorpc_test openerp.http: 'bool' object has no attribute 'get'
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/auth_signup/res_users.py", line 284, in create
    user_id = super(res_users, self).create(cr, uid, values, context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 318, in old_api
    result = method(recs, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/mail/models/res_users.py", line 45, in create
    if not values.get('login', False):
AttributeError: 'bool' object has no attribute 'get'
2015-11-30 12:24:37,848 1 ERROR odoorpc_test openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 599, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 636, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 315, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 308, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 887, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 465, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1740, in jsonrpc
    return dispatch_rpc(service, method, args)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/auth_signup/res_users.py", line 284, in create
    user_id = super(res_users, self).create(cr, uid, values, context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 318, in old_api
    result = method(recs, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/mail/models/res_users.py", line 45, in create
    if not values.get('login', False):
AttributeError: 'bool' object has no attribute 'get'

[...]

2015-11-30 12:24:38,722 1 ERROR odoorpc_test openerp.http: create() takes at least 4 arguments (3 given)
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
TypeError: create() takes at least 4 arguments (3 given)
2015-11-30 12:24:38,723 1 ERROR odoorpc_test openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 599, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 636, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 315, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 308, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 887, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 465, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1740, in jsonrpc
    return dispatch_rpc(service, method, args)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
TypeError: create() takes at least 4 arguments (3 given)

[...]

2015-11-30 12:24:40,756 1 ERROR odoorpc_test openerp.http: 'bool' object has no attribute '__getitem__'
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 1651, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/res/res_users.py", line 327, in _search
    access_rights_uid=access_rights_uid)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4721, in _search
    query = self._where_calc(cr, user, args, context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4492, in _where_calc
    domain = domain[:]
TypeError: 'bool' object has no attribute '__getitem__'
2015-11-30 12:24:40,758 1 ERROR odoorpc_test openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 599, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 636, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 315, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 308, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 887, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 465, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1740, in jsonrpc
    return dispatch_rpc(service, method, args)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 1651, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/res/res_users.py", line 327, in _search
    access_rights_uid=access_rights_uid)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4721, in _search
    query = self._where_calc(cr, user, args, context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4492, in _where_calc
    domain = domain[:]
TypeError: 'bool' object has no attribute '__getitem__'

[...]

2015-11-30 12:24:41,702 1 ERROR odoorpc_test openerp.http: 'res.users' object has no attribute 'wrong_method'
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
AttributeError: 'res.users' object has no attribute 'wrong_method'
2015-11-30 12:24:41,703 1 ERROR odoorpc_test openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 599, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 636, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 315, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 308, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 887, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 465, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1740, in jsonrpc
    return dispatch_rpc(service, method, args)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
AttributeError: 'res.users' object has no attribute 'wrong_method'

[...]

2015-11-30 12:24:43,890 1 ERROR odoorpc_test openerp.http: search() takes at least 4 arguments (3 given)
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
TypeError: search() takes at least 4 arguments (3 given)
2015-11-30 12:24:43,890 1 ERROR odoorpc_test openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 599, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 636, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 315, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 308, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 887, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 465, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1740, in jsonrpc
    return dispatch_rpc(service, method, args)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
TypeError: search() takes at least 4 arguments (3 given)

[...]

2015-11-30 12:24:50,650 1 ERROR odoorpc_test openerp.service.report: Exception: Required report does not exist: wrong_report
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/service/report.py", line 55, in exp_render_report
    result, format = openerp.report.render_report(cr, uid, ids, object, datas, context)
  File "/usr/lib/python2.7/dist-packages/openerp/report/__init__.py", line 22, in render_report
    return registry['ir.actions.report.xml'].render_report(cr, uid, ids, name, data, context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_actions.py", line 182, in render_report
    new_report = self._lookup_report(cr, name)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/ir/ir_actions.py", line 147, in _lookup_report
    raise Exception, "Required report does not exist: %s" % name
Exception: Required report does not exist: wrong_report

[...]

2015-11-30 12:25:11,483 1 ERROR odoorpc_test openerp.http: old_api() takes at least 4 arguments (3 given)
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 168, in execute_kw
    return execute(db, uid, obj, method, *args, **kw or {})
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
TypeError: old_api() takes at least 4 arguments (3 given)
2015-11-30 12:25:11,484 1 ERROR odoorpc_test openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 599, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 636, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 315, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 308, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 887, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 465, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1740, in jsonrpc
    return dispatch_rpc(service, method, args)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 168, in execute_kw
    return execute(db, uid, obj, method, *args, **kw or {})
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
TypeError: old_api() takes at least 4 arguments (3 given)

[...]

2015-11-30 12:25:14,314 1 ERROR odoorpc_test openerp.http: 'bool' object has no attribute '__getitem__'
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 168, in execute_kw
    return execute(db, uid, obj, method, *args, **kw or {})
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 1651, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/res/res_users.py", line 327, in _search
    access_rights_uid=access_rights_uid)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4721, in _search
    query = self._where_calc(cr, user, args, context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4492, in _where_calc
    domain = domain[:]
TypeError: 'bool' object has no attribute '__getitem__'
2015-11-30 12:25:14,315 1 ERROR odoorpc_test openerp.http: Exception during JSON request handling.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 599, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 636, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 315, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 308, in checked_call
    result = self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 887, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 465, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1740, in jsonrpc
    return dispatch_rpc(service, method, args)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 114, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 168, in execute_kw
    return execute(db, uid, obj, method, *args, **kw or {})
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 176, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 165, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 1651, in search
    return self._search(cr, user, args, offset=offset, limit=limit, order=order, context=context, count=count)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/addons/base/res/res_users.py", line 327, in _search
    access_rights_uid=access_rights_uid)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4721, in _search
    query = self._where_calc(cr, user, args, context=context)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 223, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4492, in _where_calc
    domain = domain[:]
TypeError: 'bool' object has no attribute '__getitem__'

[...]

2015-11-30 12:25:28,541 1 WARNING odoorpc_test openerp.addons.base.res.res_lang: Unable to get information for locale fr_FR. Information from the default locale (None) have been used.

Do you have any idea what's going on there?

MemoryError odoo.db.dump

Hi,

with small databases the dump function runs very good.
But if I try to backup a bigger system (zip file over the front end has 1.6 GB) I get this memory error.

Traceback (most recent call last):
File "./backup_odoorpc.py", line 62, in
dump = odoo.db.dump(mydbpwd, mydb,'zip')
File "/usr/local/lib/python2.7/dist-packages/odoorpc/db.py", line 131, in dump
'args': args})
File "/usr/local/lib/python2.7/dist-packages/odoorpc/odoo.py", line 264, in json
data = self._connector.proxy_json(url, params)
File "/usr/local/lib/python2.7/dist-packages/odoorpc/rpc/jsonrpclib.py", line 94, in call
return json.load(decode_data(response))
File "/usr/lib/python2.7/json/init.py", line 290, in load
**kw)
File "/usr/lib/python2.7/json/init.py", line 338, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
MemoryError

Is there a way to increase the memory?

Download report with Odoo 15

Hi,
I have tried odoorpc to download a report. I am using Odoo 15 and I am getting this error.
report.py", line 119, in download raise NotImplementedError.
So downloading report is not supported by odoorpc for odoo 15 as it requires a CSRF Token? Is that correct?
Is there any other option?

Thank you

load session file error!

I use 0.4.2,when I call odoorpc.ODOO.load after save, it raise the "invalid literal for int() with base 10:" exception. Because the session file save the timeout option "120.0", and ConfigParser can't change "120.0" to int!

How to set timezone?

I add that line:

odoo.env.context['tz'] = 'Asia/Shanghai'

But any datetime responses also UTC.

Wrong number of arguments when calling on_change method

Hello,

Im trying to call the following onchange method:

@api.onchange('fiscal_category_id',
                  'fiscal_position',
                  'invoice_line_tax_id',
                  'quantity',
                  'price_unit',
                  'discount',
                  'insurance_value',
                  'freight_value',
                  'other_costs_value')
    def onchange_fiscal(self):
        ctx = dict(self.env.context)
        if self.invoice_id.type in ('out_invoice', 'out_refund'):
            ctx.update({'type_tax_use': 'sale'})
        else:
            ctx.update({'type_tax_use': 'purchase'})

        partner_id = self.invoice_id.partner_id.id or ctx.get('partner_id')
        company_id = self.invoice_id.company_id.id or ctx.get('company_id')
        if company_id and partner_id and self.fiscal_category_id:
            result = {'value': {}}
            kwargs = {
                'company_id': company_id,
                'partner_id': partner_id,
                'partner_invoice_id': self.invoice_id.partner_id.id,
                'product_id': self.product_id.id,
                'fiscal_category_id': self.fiscal_category_id.id,
                'context': ctx
            }
            result = self.with_context(ctx)._fiscal_position_map(
                result, **kwargs)

            kwargs.update({
                'invoice_line_tax_id': [
                    (6, 0, self.invoice_line_tax_id.ids)],
                'quantity': self.quantity,
                'price_unit': self.price_unit,
                'discount': self.discount,
                'fiscal_position': self.fiscal_position.id,
                'insurance_value': self.insurance_value,
                'freight_value': self.freight_value,
                'other_costs_value': self.other_costs_value,
            })
            result['value'].update(self._validate_taxes(kwargs))
            self.update(result['value'])

So i used the suggestion given in the docs:

def on_change(record, method, args=None, kwargs=None):
    """Update `record` with the result of the on_change `method`"""
    res = record._odoo.execute_kw(record._name, method, args, kwargs)
    for k, v in res['value'].iteritems():
        setattr(record, k, v)

And called the function:

on_change(invoiceLine, 'onchange_fiscal', [],{})

But I'm getting the error:

onchange_fiscal() takes exactly 1 argument (3 given)

How to fix n+1 query?

For example, I want to traversal all fields:

Warehouse = odoo.env['stock.warehouse']
ids = Warehouse.search([])
for wh in Warehouse.browse(ids)
  print wh.write_uid

Because write_uid is a relation field, so OdooRPC will auto create n+1 query, how to optimized it?

We know in Django it can be:

Warehouse.objects.filter().select_related('write_uid')

Change web.base.url

Hi,

Process:

  1. odoo = odoorpc.ODOO("mydomain.com", port=80)
  2. odoo.login('mydb', 'user', 'password')
  3. odoo.env['ir.config_parameter'].get_param('web.base.url')

The config parameter 'web.base.url' is changed. I do not understand why this occurs. (Is registry reloaded?)

missing the tail truncation URL prior to assembly in a full URL in class ProxyHTTP

"""
def __call__(self, url, data=None, headers=None):
kwargs = {
'url': '/'.join([self._root_url, url]),
}
if data:
kwargs['data'] = encode_data(data)
request = Request(**kwargs)

add befor line 102:

if url.startswith('/'):
        url = url[1:]

because if you call the controller in this form:

odoo.http('/web/test_route/api/v0.1/get_po?external_id=9999')

we get an incorrect URL with an extra "//":

"GET //web/test_route/api/v0.1/get_po?external_id=9999 HTTP/1.0" 404 -

Differences with official webservice API?

Hi,

I am currently looking at the solutions to script the Odoo.

Now the last question that remains for me is what are exactly the differences between OdooRPC and the officially provided webservice API?
Am I mistaken in thinking that they fill the same purpose?
If so, don't you think it would be interesting in you README or in the OdooRPC FAQ to articulate these differences?

Thanks for the great work

how to load a translation with odoorpc ?

how to load translation with odoorpc ?

i tried odoo.json('/web/dataset/call_kw/base.language.install/create', { 'model': 'base.language.install', 'method': 'create', 'args': [{'lang': "zh_CN", 'overwrite': 'true'}], 'kwargs': {} } ), but it didn't work, i noticed clicking the load button will make 4 requests to the server, i need to make 4 jsonrpc call to make it work ?

thanks !

Interactive Shell

Hello,

Have future plans to create an interactive shell like erppeek

thanks

RPCError: name_get() takes exactly 1 argument (5 given)

I just tried to follow the basic step to test odoorpc but overtime that I try to use .browse I get always the same error:

RPCError: name_get() takes exactly 1 argument (5 given)

Anyone knows what this could be?
I found this when I tried odoo.env.user, and then I remade all the phases and its the .browse the error creator.

Issues sending binary data to the server

As described in #20/#21, I'm having some issues importing data into a binary field for the base_import.import model. Unfortunately I'm out of ideas, so I'd really appreciate some help here. I'm still not sure if this is something I do wrong, an OdooRPC bug, or even an odoo server bug.

Test script

I wrote this little test script which tries to import ascii data (which works) and to import non-ascii data in various ways.

All those examples are Python 3, i.e. 'tést' is a python3 str (python2 unicode) and .encode() gives us a python3 bytes.

test 2: utf-8 data as plaintext (bytes)

This tries to send 'id,name\nimport_test.test2,tést'.encode('utf-8') which causes:

Traceback (most recent call last):
  File "encoding_test.py", line 44, in main
    create_id(env, 'id,name\nimport_test.test2,tést'.encode('utf-8'))
  File "encoding_test.py", line 15, in create_id
    import_id = env.create(payload)
  File "/home/florian/proj/odoo/.venv/lib/python3.4/site-packages/odoorpc/models.py", line 72, in rpc_method
    cls._name, method, args, kwargs)
  File "/home/florian/proj/odoo/.venv/lib/python3.4/site-packages/odoorpc/odoo.py", line 468, in execute_kw
    'args': args_to_send})
  File "/home/florian/proj/odoo/.venv/lib/python3.4/site-packages/odoorpc/odoo.py", line 263, in json
    data = self._connector.proxy_json(url, params)
  File "/home/florian/proj/odoo/.venv/lib/python3.4/site-packages/odoorpc/rpc/jsonrpclib.py", line 84, in __call__
    "id": random.randint(0, 1000000000),
  File "/usr/lib/python3.4/json/__init__.py", line 230, in dumps
    return _default_encoder.encode(obj)
  File "/usr/lib/python3.4/json/encoder.py", line 192, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.4/json/encoder.py", line 250, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.4/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'id,name\nimport_test.test2,t\xc3\xa9st' is not JSON serializable

test 3: utf-8 data as plaintext (string)

This tries to simply send an unicode object (python3 str), which fails on the server:

Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 537, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 574, in dispatch
    result = self._call_function(**self.params)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 310, in _call_function
    return checked_call(self.db, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 307, in checked_call
    return self.endpoint(*a, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 803, in __call__
    return self.method(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 403, in response_wrap
    response = f(*args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 1595, in jsonrpc
    return dispatch_rpc(service, method, args)
  File "/usr/lib/python2.7/dist-packages/openerp/http.py", line 115, in dispatch_rpc
    result = dispatch(method, params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 162, in execute_kw
    return execute(db, uid, obj, method, *args, **kw or {})
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 170, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/service/model.py", line 159, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 336, in old_api
    result = method(recs, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4077, in create
    record = self.browse(self._create(old_vals))
  File &ouot;/usr/lib/python2.7/dist-packages/openerp/api.py", line 239, in wrapper
    return new_api(self, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/api.py", line 463, in new_api
    result = method(self._model, cr, uid, *args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/openerp/models.py", line 4176, in _create
    updates.append((field, '%s', current_field._symbol_set[1](vals[field])))
  File "/usr/lib/python2.7/dist-packages/openerp/osv/fields.py", line 602, in <lambda>
    _symbol_f = lambda symb: symb and Binary(str(symb)) or None
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 27: ordinal not in range(128)

I investigated the source where the error occurs, where there's this comment:

Binary values may be byte strings (python 2.6 byte array), but the legacy OpenERP convention is to transfer and store binaries as base64-encoded strings. The base64 string may be provided as a unicode in some circumstances, hence the str() cast in symbol_f. This str coercion will only work for pure ASCII unicode strings, on purpose - non base64 data must be passed as a 8bit byte strings.

So I tried if base64 would work:

test 4: utf-8 as encoded base64

This tries to send base64.b64encode('id,name\nimport_test.test4,tést'.encode('utf-8')) which fails on the client, like with test 2:

Traceback (most recent call last):
  [...]
  File "/usr/lib/python3.4/json/encoder.py", line 173, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: b'aWQsbmFtZQppbXBvcnRfdGVzdC50ZXN0NCx0w6lzdA==' is not JSON serializable

test 5: utf-8 as base64 str

This seems to work, but it looks like the server actually stores the base64 as data in the database, which causes this response when parse_preview is called:

{'error': 'CSV file seems to have no content', 'preview': 'aWQsbmFtZQppbXBvcnRfdGVzdC50ZXN0NSx0w6lzdA=='}

So if I understand correctly, base_import.import doesn't expect its data as base64, but there's no way to transfer non-ASCII data via the json-RPC API? Is there something I'm missing?

I also tried adjusting the script and running it with Python 2, with the same outcome.

Do not forward underscore prefixed functions to server

When trying to use OdooRPC from iPython, just running client.env['res.users'] fails with Access Denied ("Private methods (such as ipython_display) cannot be called remotely.").

Is there a reason OdooRPC should forward accesses to these to Odoo at all?

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.