This question has been flagged
2 Replies
1326 Views

Hello,

I have another question

I am trying to write a python script to import a csv document from a folder to the odoo database by using the xmlr-rcp procedure.

Here my problem:

- if i launch the program with python2, the "product.template" doesn't exist and I don't know why

- if i launch it with python3, xmlrpclib can't be found

Here the script:

import csv
import xmlrpclib

#=============================================================================#
#=============================== INTRODUCTION ================================#

username="adress"
pwd = "mdp"
dbname = "bitnami_odoo"

sock_common = xmlrpclib.ServerProxy("http://localhost:8080/xmlrpc/common")
uid = sock_common.login(dbname, username, pwd)
sock = xmlrpclib.ServerProxy("http://localhost:8080/xmlrpc/object")

reader =csv.reader(open('fichier.csv', 'rb'))
for row in reader:
print(row[1])
product_template = {
'name':row[1],
'standard_price':row[2],
'list_price':row[2],
'mes_type':'fixed',
'uom_id':1,
'uom_po_id':1,
'type':'product',
'procure_method':'make_to_tock',
'cost_method':'standard',
'categ_id':1}
template_id=sock.execute(dbname,uid,pwd, 'product.template', 'create', product_template)

product_product = {
'product_tmp1_id':template_id,
'default_code':row[0],
'active': True,
}

product_id = sock.execute(dbname, pwd, 'product.product', 'create', product_product)


Thank you!

Avatar
Discard
Author Best Answer

Oh thank you very much I will try!

Avatar
Discard
Best Answer

Hello,

could you just make sure that "product" application installed on your database: "bitnami_odoo" ?

For python2 : import xmlrpclib should work.

for python3  : You can import the client from xmlrpc.client. you have to use : import xmlrpc.client

then

sock_common = xmlrpc.client.ServerProxy("http://localhost:8080/xmlrpc/common")


Thanks 





Avatar
Discard