Odoo Help


PHP xmlrpc multiple products - TypeError: string indices must be integers, not str

Bas Debie
on 11/13/13, 7:34 AM 2,412 views


Working on pushing orders to open erp from our webshops orders but getting an error in open erp xmlrpc request .

I received instructions to make this request to open erp:

'lines':[{'product_cod':'ZOIX333','qty':1.0,'price_unit':366.00,'discount_pct':0.0,'taxes':33.00,'tax_included':True}], #{...},{},{}]

I created this in PHP to test:

$order_line_items = array( 'product_cod' => new xmlrpcval('ZWWX4135', "string") ,

'qty' => new xmlrpcval('1.0', "string") ,

'price_unit' => new xmlrpcval('166.00', "string") ,

'discount_pct' => new xmlrpcval('0.0', "string") ,

'taxes' => new xmlrpcval('16.44', "string") ,

'tax_included' => new xmlrpcval('true', "string")


And then in request:

'lines' => new xmlrpcval($order_line_items, "struct") ,

But then I get an error:

File "/opt/openerp-6.1-extra-addons/mod_ext/remote/remote_sync.py", line 303, in _import_sale_order product_ids=product_obj.search(cr,uid,[('default_code','=',payload_line['product_cod'])],context=context) TypeError: string indices must be integers, not str

Hopefully someone can point me in the right direction. Any help is highly appreciated! Thanks, Bas

Jos De Graeve
On 12/24/14, 10:33 AM

Hi Bas,

the 'lines' attribute is a one2many field.  In order to update values on this, you need to use a special syntax as defined in https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.write

In python you must pass an array of tuples like this:

'lines': [(0,0,{'field_a':'value1','field_b':'value2'}),(0,0,{'field_a':'value3','field_b':'value4'})],

In php, this will get quite messy unfortunately because you must encapelate everything in a huge stack of xmrpcval objects.  The value you need to pass is actualy a list of tuples containing dictionairies, in php this will be an array of arrays containing structs.



Bas Debie
On 12/24/14, 1:29 PM

Hi Jos,

At the time I was new to xml-rpc / odoo, and the PHP xml-rpc library documentation is very limited and it didn't answer my question.

However, solution was quite simple and completely inline with your answer...
This did the trick:

$order_line_items[] = new xmlrpcval(array(
                        'product_cod'    =>         new xmlrpcval("ZZZE1090", "string") , 
                        'name'            =>         new xmlrpcval($transport_name, "string") , 
                        'qty'            =>         new xmlrpcval("1", "double") , 
                        'price_unit'    =>         new xmlrpcval($shipping_ex_vat, "double") ,  // incl BTW
                        'discount_pct'    =>         new xmlrpcval('0.0', "double") , 
                        'taxes'            =>         new xmlrpcval('0.00', "double") ,
                        'tax_included'    =>         new xmlrpcval('0', "boolean")
), "struct");    

And in calling the payload:

'lines'                =>            new xmlrpcval($order_line_items, "array") , 

However, if I run into similar problem in future, I know who to ask ;-)

Enjoy the holidays!

About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 11/13/13, 7:34 AM
Seen: 2412 times
Last updated: 3/16/15, 8:10 AM