hedgethe
hedgethe

Reputation: 55

Odoo 13 creating a sales record via api?

Hi I am trying to create a sales record via the odoo 13 api, I have looked at the documentation and so far I have not been able find any example, I have also asked on there forums but so far no luck. Does anyone have an example I can see?

Upvotes: 0

Views: 1229

Answers (1)

Kenly
Kenly

Reputation: 26748

I used the following example to create a sale order using an instance of odoo.com

import xmlrpc.client

url = "https://***.odoo.com"
db = ""
username = ""
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))

# Get partner_id and product_ids from database
# Or create them

so_id = models.execute_kw(db, uid, password, 'sale.order', 'create', [{
    'partner_id': partner_id,
    'order_line': [(0,0, {'product_id': product_id}) for product_id in product_ids]
}])

Upvotes: 4

Related Questions