Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Making a request for data with C#.NET

By
Hans-Henrik G. Møller
on 12/4/14, 8:13 AM 2,053 views

Hi,

I am working on creating a small tool to work with the XML-RPC service for a hosted Odoo instance. I have managed to create the connection and authenticate, but having difficulties creating a request properly. Seems that I can not pick the correct datatype.

The php code looks like this:

$models->execute_kw($db, $uid, $password,

    'res.partner', 'search_read',
    array(array(array('is_company', '=', true),
                array('customer', '=', true))),
    array('fields'=>array('name', 'country_id', 'comment'), 'limit'=>5));

My C# code to create the parameter array looks like this:

            //search criterias
            object[] c1 = new object[] { "name", "=", "Lunderskov Boldklub" };

            //list of all criterias
            object[] criterias = new object[] { c1 };

            //fields defs

            object[] defs = { new object[] { "fields", new object[] { "name", "country_id", "comment" } }, new object[] {"limit", 5}}; 

            //parameters
            object[] parms = new object[] { criterias, defs };

Now.. the Odoo response is:

<?xml version='1.0'?>
<methodResponse>
<fault>
<value><struct>
<member>
<name>faultCode</name>
<value><string>unhashable type: 'list'</string></value>
</member>
<member>
<name>faultString</name>
<value><string>Traceback (most recent call last):
  File "/home/odoo/src/odoo/8.0/openerp/service/wsgi_server.py", line 75, in xmlrpc_return
    result = openerp.http.dispatch_rpc(service, method, params)
  File "/home/odoo/src/odoo/8.0/openerp/http.py", line 108, in dispatch_rpc
    result = dispatch(method, params)
  File "/home/odoo/src/odoo/8.0/openerp/service/model.py", line 37, in dispatch
    res = fn(db, uid, *params)
  File "/home/odoo/src/odoo/8.0/openerp/service/model.py", line 162, in execute_kw
    return execute(db, uid, obj, method, *args, **kw or {})
  File "/home/odoo/src/odoo/8.0/openerp/service/model.py", line 113, in wrapper
    return f(dbname, *args, **kwargs)
  File "/home/odoo/src/odoo/8.0/openerp/service/model.py", line 170, in execute
    res = execute_cr(cr, uid, obj, method, *args, **kw)
  File "/home/odoo/src/odoo/8.0/openerp/service/model.py", line 159, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/home/odoo/src/odoo/8.0/openerp/api.py", line 237, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/odoo/src/odoo/8.0/openerp/models.py", line 5061, in search_read
    result = self.read(cr, uid, record_ids, fields, context=read_ctx)
  File "/home/odoo/src/odoo/8.0/openerp/api.py", line 237, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/odoo/src/odoo/8.0/openerp/models.py", line 3078, in read
    result = BaseModel.read(records, fields, load=load)
  File "/home/odoo/src/odoo/8.0/openerp/api.py", line 235, in wrapper
    return new_api(self, *args, **kwargs)
  File "/home/odoo/src/odoo/8.0/openerp/models.py", line 3102, in read
    if name in self._columns:
TypeError: unhashable type: 'list'
</string></value>
</member>
</struct></value>
</fault>
</methodResponse>

So.. how should I create the last part of the request?

1

I solved the problem myself finally. This code works..

 

            XmlRpcStruct d = new XmlRpcStruct();
            d.Add("fields", new object[] { "name", "country_id", "comment"});
            d.Add("limit", 5);

 

Thanks for posting the solution to your own question so that the next person might benefit from your solution.

Stephen Mack
on 12/6/14, 3:19 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/4/14, 8:13 AM
Seen: 2053 times
Last updated: 5/12/16, 5:51 AM