cucuru
cucuru

Reputation: 3718

xmlrpc search in odoo database

Im using xmlrpc to search data in my postgres odoo database.

When searching in table such res_partner everything is fine.

Now I want to search in res_partner_title, but it doesn't return the ID.

My database content:

myDatabase=# select * from res_partner_title;

id | create_uid |        create_date         |   name    | shortcut | write_uid |         write_date         
----+------------+----------------------------+-----------+----------+-----------+----------------------------
 1 |          1 | 2017-12-29 09:26:11.139936 | Madam     | Mrs.     |         1 | 2017-12-29 09:26:11.139936
 2 |          1 | 2017-12-29 09:26:11.139936 | Miss      | Miss     |         1 | 2017-12-29 09:26:11.139936
 3 |          1 | 2017-12-29 09:26:11.139936 | Sir       | Sr.      |         1 | 2017-12-29 09:26:11.139936
 4 |          1 | 2017-12-29 09:26:11.139936 | Mister    | Mr.      |         1 | 2017-12-29 09:26:11.139936
 5 |          1 | 2017-12-29 09:26:11.139936 | Doctor    | Dr.      |         1 | 2017-12-29 09:26:11.139936
 6 |          1 | 2017-12-29 09:26:11.139936 | Professor | Prof.    |         1 | 2017-12-29 09:26:11.139936
(6 rows)

my code:

 myData = myObject.search('res.partner.title', [('shortcut','=','Mr.')])

class MyClass:
def __init__(self, host, port, username, pwd, dbname, context, dbsuperpwd=None,
             dbuser=None, dbpasswd=None):

    self.sock_common = xmlrpclib.ServerProxy ("http://" + host + ":" + str(port) + "/xmlrpc/common")
    self.uid = self.sock_common.login(dbname, username, pwd)    
    self.sock = xmlrpclib.ServerProxy("http://" + host + ":" + str(port) + "/xmlrpc/object")
    self.dbname = dbname
    self.pwd = pwd
    self.dbsuperpwd = dbsuperpwd
    self.context = context



def search(self, modelname, query, offset=0, limit=0, order=False,
           context=None):
    context = context or self.context


    for i in range(MAX_RETRIES):
        try:
            return self.sock.execute(self.dbname, self.uid, self.pwd,
                                     modelname, 'search', query, offset,
                                     limit, order, context)
        except socket.error:
            pass

It returns always 1, no matter the filter is.

How can I get 3 (in my example)?

EDIT (adding comment asked data)

context = {'lang': 'es_ES'}

it returns 1 or 0

I've just discovered, it works in odoo9 and fails in odoo10

Upvotes: 0

Views: 1218

Answers (1)

forvas
forvas

Reputation: 10189

I guess the problem could be the language. You're sending in context es_ES and looking for the shorcut in English, so now try for example to replace your current search domain with [('shortcut','ilike','%Sr.%')].

Take a look at ir_translation table:

  id  | lang  |  src   |            name            | type  | module |   state    | comments | value | res_id 
------+-------+--------+----------------------------+-------+--------+------------+----------+-------+--------
 6483 | es_ES | Mister | res.partner.title,name     | model | base   | translated |          | Señor |      3
 6559 | es_ES | Mr.    | res.partner.title,shortcut | model | base   | translated |          | Sr.   |      3

Upvotes: 1

Related Questions