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.

0

How to import data with External ID's through XMLRPC

By
Djordje Marjanovic
on 6/3/15, 10:28 AM 1,343 views

Hi all,

I am trying to import customers from a CSV file into Odoo 8 via XMLRPC. I was wondering what I need to do to also include External IDs associated with each customer in the import. Here is my code:

  #!/usr/bin/env python

import csv
from xmlrpclib import ServerProxy

SERVER = 'http://localhost:8069'
DATABASE = 'testcompany'
USERNAME = 'admin'
PASSWORD = 'password'

server = ServerProxy('http://localhost:8069/xmlrpc/common')
user_id = server.login(DATABASE, USERNAME, PASSWORD)

server = ServerProxy('http://localhost:8069/xmlrpc/object')

def search(list, key):
    for item in list:
        return item[key]

reader = csv.reader(open('ODOO_clientsMain2_test.csv','rb'))

for row in reader:
   partner_template = {
        'name': row[0],
 } if row[2] is not None and row[2]<>'': partner_template.update({'email': row[2]}) if row[5] is not None and row[5]<>'': partner_template.update({'tin': row[5]}) if row[6] is not None and row[6]<>'': partner_template.update({'ref': row[6]})
 if row[8] is not None and row[8]<>'': partner_template.update({'phone': row[8]}) if row[9] is not None and row[9]<>'': partner_template.update({'mobile': row[9]})

 print partner_template partner_id = server.execute_kw(DATABASE, user_id, PASSWORD, 'res.partner', 'create', [partner_template]) if row[7] is not None and row[7]<>'': #look up and update payment term payment_term_id = server.execute_kw(DATABASE, user_id, PASSWORD, 'account.payment.term', 'search_read', [[['name','=',row[7]],['active', '=', True]]],{'fields': ['id'], 'limit': 1}) if payment_term_id is not None: id = server.execute_kw(DATABASE, user_id, PASSWORD, 'res.partner', 'write', [[partner_id],{'property_payment_term': search(payment_term_id,'id')}]) if row[10] is not None and row[10]<>'': #look up and update pricelist pricelist_id = server.execute_kw(DATABASE, user_id, PASSWORD, 'product.pricelist', 'search_read', [[['name','=',row[10]],['active', '=', True]]],{'fields': ['id'], 'limit': 1}) if pricelist_id is not None: id = server.execute_kw(DATABASE, user_id, PASSWORD, 'res.partner', 'write', [[partner_id],{'property_product_pricelist': search(pricelist_id,'id')}])

Thank you.

Did you ever resolve this?

Bista Solutions US, Ray Carnes
on 7/22/16, 10:00 PM
0
Djordje Marjanovic
On 7/22/16, 10:15 PM

Yes, here is the missing part:

#create External ID
external_ids = {
'model': 'res.partner',
'name': row[11],
'res_id': partner_id,
}
external_id = server.execute_kw(DATABASE, user_id, PASSWORD, 'ir.model.data', 'create', [external_ids])

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: 6/3/15, 10:28 AM
Seen: 1343 times
Last updated: 7/23/16, 3:52 AM