Odoo Help


How to write One2many field using xmlrpc ?

Jignesh Mehta
on 10/20/15, 5:47 AM 3,312 views

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,


Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
Serpent Consulting Services Pvt. Ltd.
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. is an Official Odoo Partner, working on Odoo ever since 2007, experience of 11+ years and witnessed the growth of Odoo.

We are a team of 80+ experts on various verticals. Our portfolio of products can be seen at http://www.serpentcs.com and http://www.serpentcs.in

Our Expertise and Services:

  • Odoo Support

  • Odoo Development

  • Odoo Training

  • Odoo Migration

  • Odoo Implementation

  • Odoo Consulting

Our 290+ Apps on Appstore : https://apps.odoo.com/apps/modules/browse?author=Serpent Consulting Services Pvt. Ltd.


Serpent Consulting Services Pvt. Ltd.
On 10/20/15, 6:09 AM

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, [])    

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 "product_migration.py", line 143, in 'delay' : source_user1['delay'] or False, KeyError: 'delay' delay field already in the "product.supplierinfo".

Jignesh Mehta
on 10/20/15, 6:34 AM

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.

Serpent Consulting Services Pvt. Ltd., Serpent Consulting Services Pvt. Ltd.
on 10/20/15, 8:00 AM

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

Jignesh Mehta
on 10/20/15, 9:08 AM

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

2 follower(s)


Asked: 10/20/15, 5:47 AM
Seen: 3312 times
Last updated: 4/25/16, 2:55 AM