Skip to Content
Menu
This question has been flagged
1 Reply
5268 Views

Let me first state I am new to Python and still learning some of the data types and how to construct them.

I am trying to build a list of criteria to pass to the XML RPC. This page (https://www.odoo.com/documentation/8.0/reference/orm.html#reference-orm-domains) states a list of criteria can be passed using triple tuples. So... I 'm trying to construct a tuple of tuples I can pass to the XML RPC.

Can someone help me understand what I'm doing wrong?


EXAMPLE OF TUPLE BEING CREATED:

for k,v in search_conditions.items():

    name = k
    val = v
    conditions = conditions + (name,'=',val)

  EXAMPLE OF PASSING conditions to the XML RPC

sock.execute(dbname, uid, pwd, model, 'search', conditions)

ERROR I GET:

if not any(item[0] == \'active\' for item in domain):\n File "/opt/odoo/odoo/openerp/models.py", line 4438, in <genexpr>\n if not any(item[0] == \'active\' for item in domain):\nTypeError: \'int\' object has no attribute \'__getitem__\'\n'> 

Avatar
Discard
Author Best Answer

I was finally able to figure this out and wanted to share it with the community in case someone else could use it.

The reason for this need was I found myself having to repeat a lot of the same code for interacting with different models. The function I created now allows me to pass a list of conditions to a function and perform various checks, changes, and calls in a reusable function. This allowed me to eliminate over 100 lines of codes.

The only caveat I was not able to control the order of the criteria in the dictionary so I could not figure out how to easily pass an "OR" condition such as "['active','=',True],'|',['active','=',False]". Adding the active conditions caused the whole XMLRPC search to break because it changed the order of the criteria to be ordered alphabetically instead of the order I added it to the dictionary. If anyone has a solution for this please let me know.

FIRST CREATE THE DICTIONARY WITH THE DESIRED CRITERIA

search_conditions = {'someField':True,'type': 'default'} 

ITERATE THROUGH DICTIONARY TO CREATE LIST OF TUPLES TO BE USED WITH XML RPC 

        for k,v in search_conditions.items():
name = k
val = v 
condition = [name,'=',val]  
condition = va
conditions.append(condition)

EXECUTE XMLRPC SEARCH

sock.execute(dbname, uid, pwd, model, 'search', conditions)

Avatar
Discard
Related Posts Replies Views Activity
1
Oct 24
268
1
Apr 24
513
2
Mar 24
742
0
Sep 23
575
1
Jun 23
818