Skip to Content
Menu
This question has been flagged
2 Replies
10858 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.

Avatar
Discard

Did you ever resolve this?

Author Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
7
May 20
4959
0
Apr 16
2111
2
Apr 15
4771
11
Sep 21
30054
2
Jan 24
13593