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.

2

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

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

Hi,

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

1
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.

Regards,

Jos

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

Hi Jos,
Thanks...

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!
Bas

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: 11/13/13, 7:34 AM
Seen: 2158 times
Last updated: 3/16/15, 8:10 AM