How to write One2many field using xmlrpc ?

Jignesh Mehta

In product migration, one field which is one2many (Suppliers) write using xmlrpc script. The below is my code for write field.

Method for write One2many field :-

if product['seller_ids']:

    seller_list = []

    for seller in product['seller_ids']:

        source_user1 = source_sock.execute(source_db, source_userId, source_password, 'product.supplierinfo', 'read', seller, ['name']) 

        dest_user = destination_sock.execute(destination_db, destination_userId, destination_password, 'product.supplierinfo', 'search', [('name', '=', source_user1['name'])]) 

         if dest_user:



            seller_vals = {

                 'name' : source_user1['name'],

                'delay' : source_user1['delay'],

                'min_qty' : source_user1['min_qty'],

                'company_id' : company_id or False,


            new_dest_user = destination_sock.execute(destination_db, 1, destination_password, 'product.supplierinfo', 'create', seller_vals)



    seller_list = []

In fields :-

'seller_ids' : [(4, 0, seller_list)] or False,

1 Answer
Best Answer

Hello Jignesh,

At the end of the method add following code to add reference of product template in "product.supplierinfo".

destination_sock.execute(destination_db, 1, destination_password, 'product.supplierinfo', 'write', seller_list, {'product_tmpl_id': product['product_tmpl_id']})

Hope this will help you.


The type of field values to pass in "vals" for relationship fields is specific:

For a one2many field, a lits of tuples is expected.

Here is the list of tuple that are accepted, with the corresponding semantics:

  • (0, 0, { values }) link to a new record that needs to be created with the given values dictionary

  • (1, ID, { values }) update the linked record with id = ID (write *values* on it)

  • (2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)


[(0, 0, {'field_name':field_value_record1, ...}), (0, 0, {'field_name':field_value_record2, ...})]



You are reading 'name' field only from product.supplierinfo table. You should either pass list of fields in read method or can pass blank "[]" which will read value of those particular fields or all the fields (in the case of blank list).

Like this:

source_user1 = source_sock.execute(source_db, source_userId, source_password, 'product.supplierinfo', 'read', seller, [])    
Jignesh Mehta

Hello SerpentTeam, I have update code and also update seller vals, but i am still facing error. updated vals :- seller_vals = { 'name' : source_user1['name'] or False, 'delay' : source_user1['delay'] or False, 'min_qty' : source_user1['min_qty'] or False, 'company_id' : company_id or False, } Error Log :- Traceback (most recent call last): File "", line 143, in 'delay' : source_user1['delay'] or False, KeyError: 'delay' delay field already in the "product.supplierinfo".

You are only reading 'name' field from product.supplierinfo table as you are passing only ['name'] in the read method during rpc call. See my updated answer please.

Jignesh Mehta

Thank u so much @Serpent Consulting Services Pvt. Ltd.