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

XML RPC Question - trying to construct a tuple of tuples - getting 'INT object has no attribute GETITEM' error

By
Jesse Rye
on 7/29/15, 5:53 PM 775 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'> 

1
Jesse Rye
On 8/9/15, 12:42 AM

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)

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: 7/29/15, 5:53 PM
Seen: 775 times
Last updated: 9/16/16, 12:07 AM