Skip to Content
Menu
This question has been flagged
2 Replies
18231 Views

I have installed the Community edition of Odoo 11, and the inventory module.

Using Python I can read the product.product table.

However, I have not successfully managed to add a product.  Since I have more than 1000 products to add, I would rather not add them individually.  I also have not find a way to upload products from a CSV file.

I looked for all required fields and included them in the object to add.

Please advise what I am doing wrong.  There is no description in the fault esponse for the failure, just the code '2'.


The code I tried follows.  (Python 3)

import xmlrpc.client

from pprint import pprint

url = 'http://<myodoo>:8069'

db = '<myodoo-db>'

username = '<username>'

password = '<password>'

common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))

uid = common.authenticate(db, username, password, {})

models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))

pprint(common.version())

pprint(models.execute_kw(db, uid, password, 'product.product', 'check_access_rights', ['create'], {'raise_exception': False}))

prodid = models.execute_kw(db, uid, password, 'product.product', 'create', [{

'categ_id': 1,

'name': 'Yet another thing',

'responsible_id': 7,

'tracking': 'none',

'type': 'product',

'uom_id': 1,

'uom_po_id': 1,

'create_uid': 7, }])

The results are:

{'protocol_version': 1,

'server_serie': '11.0',

'server_version': '11.0-20180110',

'server_version_info': [11, 0, 0, 'final', 0, '']}

True

Traceback (most recent call last):

File "connect.py", line 151, in <module>

'create_uid': 7, }])

File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/xmlrpc/client.py", line 1089, in __call__

return self.__send(self.__name, args)

File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/xmlrpc/client.py", line 1419, in __request

verbose=self.__verbose

File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/xmlrpc/client.py", line 1131, in request

return self.single_request(host, handler, request_body, verbose)

File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/xmlrpc/client.py", line 1147, in single_request

return self.parse_response(resp)

File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/xmlrpc/client.py", line 1318, in parse_response

return u.close()

File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/xmlrpc/client.py", line 656, in close

raise Fault(**self._stack[0])

xmlrpc.client.Fault: <Fault 2: ''>

Avatar
Discard
Best Answer

Try removing the `create_uid`

I think this is auto created from the `uid` you pass with the db etc.

Avatar
Discard
Best Answer

You can update the code something like,

import xmlrpc.client
host='localhost'
port=8069
url = "http://localhost:8069/xmlrpc"
db = 'test_website'
username = 'admin'
password = 'a'
print ("URLL", url)
common = xmlrpc.client.ServerProxy(url +'/common')
uid = common.login(db, username, password)
print ("UIDDD", uid)
models = xmlrpc.client.ServerProxy(url +'/object')
prodid = models.execute_kw(db, uid, password, 'product.template', 'create', [{
    'categ_id': 1,
    'name': 'Yet another thing',
    'uom_id': 1,
    'uom_po_id': 1,
  }])

Avatar
Discard