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.

7

How to write One2many field using xmlrpc ?

By
Jignesh Mehta
on 10/20/15, 5:47 AM 1,599 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_list.append(dest_user[0])

        else:

            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.append(new_dest_user)

else:

    seller_list = []


In fields :-

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



4

Serpent Consulting Services Pvt. Ltd.

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

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

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)

Example:

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

----------------------------------------------------------------------------------------------------------------------------

Edit:

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

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

2 follower(s)

Stats

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