Trying to oerp.create records, getting cryptic error messages

Asked by stephan stachurski

I'm trying to follow the procedures given in the docs under Tutorials > Execute Queries https://pythonhosted.org/OERPLib/tutorials.html#execute-queries.

I would like to create a user, so I've tried to do this:

import oerplib
oerp = oerplib.OERP('localhost',protocol='xmlrpc', port=8069)
u = oerp.login('admin','***','my_db')
wb = oerp.create('res.user', {'name':'Foo Bar', 'login':'foob'})

and the response is:

---------------------------------------------------------------------------
RPCError Traceback (most recent call last)
<ipython-input-23-db916ec9957e> in <module>()
----> 1 wb = oerp.create('res.user', {'name':'Wolfgang Boehmer', 'login':'wolfgangb'})

/usr/local/lib/python2.7/dist-packages/oerplib/oerp.pyc in create(self, model, vals, context)
    427 :raise: :class:`oerplib.error.RPCError`
    428 """
--> 429 return self.execute(model, 'create', vals, context)
    430
    431 def read(self, model, ids, fields=None, context=None):

/usr/local/lib/python2.7/dist-packages/oerplib/oerp.pyc in execute(self, model, method, *args)
    248 model, method, *args)
    249 except rpc.error.ConnectorError as exc:
--> 250 raise error.RPCError(exc.message, exc.oerp_traceback)
    251
    252 def execute_kw(self, model, method, args=None, kwargs=None):

RPCError: 2

I'm not really sure what RPCError 2 is supposed to mean. Is it possible to get more detailed error messages, like, am I missing fields? Are the values of fields not valid?

Some context for my question:

I'm new to OpenERP and I'm beginning to play around with openerp-client-lib and oerplib. I'm trying to import some data from a flat csv file, which contains information about contacts, partners and companies. Each row represents a contact, but based on the contents of the row it could also be that the contact is a partner, and is associated with a company. Contacts can also be associated with a sales person.

When importing this CSV in the web interface, I get validation errors that "No matching record found for name 'Foo Bar' in field 'Salesperson' at row 2. It does not seem possible to configure the import process to create a related record if no matching records exist, which is why I started to explore the idea of importing these records in a script.

Question information

Language:
English Edit question
Status:
Answered
For:
OERPLib Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Sébastien Alix (sebastien-alix) said :
#2

Hi,

To answer you, yes, it would be possible to get more detailled messages. It is just that OpenERP has changed the way they return error code through RPC, and I need to look at this more closely to better handle errors. Some work has to be done here for sure.

About your problem, can you give me the version of OERPLib and OpenERP/Odoo used?
Also, is the error raising if you write your code as below?

  user_obj = oerp.get('res.users')
  user_obj.create({'name':'Wolfgang Boehmer', 'login':'wolfgangb'})

Regards,

Revision history for this message
stephan stachurski (ses1984) said :
#3

The code you suggested worked.

I'm using OERPLib version 0.8.2 and OpenERP 7.0-20140804-231303.

I have a follow up question, this may not be strictly related to oerplib but maybe related to xml rpc proxy servers.

One technique that I routinely use to explore new libraries and APIs is to load them in an ipython shell and play with them, using tab completion to see what kind of attributes and methods are available on objects.

After I call oerp.get('res.users'), the resultant object doesn't seem to have a create method, it looks like it just has browse and fields_reserved, at least not according to ipython tab completion:

In [4]: user_obj = oerp.get('res.users')

In [5]: user_obj
Out[5]: Model('res.users')

In [5]: user_obj. # tab completion attempted here
user_obj.browse user_obj.fields_reserved

Is it documented anywhere what methods or attributes are really available on Model type objects?

Thanks very much for your fast response.

Revision history for this message
Sébastien Alix (sebastien-alix) said :
#4

Indeed, there is no methods (except 'browse()') implemented in Model proxies object generated by OERPLib. And there is no way to get the list of methods supported by a Model class through RPC... the only option is to read the code.

But regarding common methods, you can read the code of the Model class of the server (inside the 'openerp/osv/orm.py' file if I remember correctly), at least that's the best way to grab information. Some technical documentation are available here too: https://www.odoo.com/forum/help-1/question/what-documentation-is-available-for-odoo-60312

Note: thanks for pointing 'fields_reserved', this field should be protected, I have to fix that ;)

Regards,

Revision history for this message
Sébastien Alix (sebastien-alix) said :
#5

Answered

Can you help with this problem?

Provide an answer of your own, or ask stephan stachurski for more information if necessary.

To post a message you must log in.