Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
16077 Vistas

Hi, I spend more than three hours trying to understand how to create an order using Odoo 11 and Python with no luck.

The smallest example I came to is this:

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

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

order = models.execute_kw(db, uid, password, 'sale.order', 'create', {

     'name': 'new sale order',

})


But I get:


File "./conexion.py", line 29, in <module>

'name': 'new sale order',

File "/usr/lib/python2.7/xmlrpclib.py", line 1243, in __call__

return self.__send(self.__name, args)

File "/usr/lib/python2.7/xmlrpclib.py", line 1602, in __request

verbose=self.__verbose

File "/usr/lib/python2.7/xmlrpclib.py", line 1283, in request

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

File "/usr/lib/python2.7/xmlrpclib.py", line 1316, in single_request

return self.parse_response(response)

File "/usr/lib/python2.7/xmlrpclib.py", line 1493, in parse_response

return u.close()

File "/usr/lib/python2.7/xmlrpclib.py", line 800, in close

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

xmlrpclib.Fault: <Fault 2: ''>


What's wrong with my code?.


Avatar
Descartar
Autor Mejor respuesta

Hi Chandni, thanks for your answer.

After running your code (with some changes to update to Python3) I've got this error:

xmlrpc.client.Fault: <Fault warning -- Object sale.order doesn't exists: ''>

About your code, why do you use /xmlrpc/object and /xmlrpc/common instead of /xmlrpc/2/object and /xmlrpc/2/common? which Odoo version are you running?.

Leonardo.



Avatar
Descartar
Autor

I found the solution. I had to install the Sales Management module.

Mejor respuesta

Hello,

When we create sale order, there must be one partner (Customer) Selected for that.

It is not defined in your python script; the mandatory fields are : partner_id, pricelist_id and date_order

Name will be taken automatically, but mandatory information must be added. (Date is taken automatically from default vale setting.)

Try this: (I have created in my local from this, successfully)


#!/usr/bin/env python

# coding: utf-8

import xmlrpclib

import xlrd

dbname = 'test'

username = 'admin'

pwd = 'a'

sock_common = xmlrpclib.ServerProxy ('http://localhost:8069/xmlrpc/common')

sock = xmlrpclib.ServerProxy('http://localhost:8069/xmlrpc/object')

uid = sock_common.login(dbname, username, pwd)

account_ids = sock.execute(dbname, uid, pwd, 'sale.order', 'create', {'partner_id': 1, 'pricelist_id':1})

print "Sale Order Created Successfully...!"


If this is helpful to you, please upvote this answer and mark right.


Thanks,

Chandni.

Avatar
Descartar