Ahmad Sabeh
Ahmad Sabeh

Reputation: 556

Create an invoice from a sales order using XML-RPC (Python)

I'm following the external APIs documentation : https://www.odoo.com/documentation/13.0/webservices/odoo.html

to implement our companies requirements. I'm required to create a sales order and automatically create an invoice after that. The sales order part is done but I cant seem to be able to attach the Invoice to the Sales order

I've tried linking it via the 'invoice_ids' field but the documentation does not mention how to provide a many2many field in it. here is the code:

many2manyInvoice =  [(4, invoice_id)]   

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

#Admin user Id
uid = common.authenticate(db, username, password, {})

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

models.execute_kw(db, uid, password, 'sale.order', 'write', [[sales_order_id],     {'invoice_ids':many2manyInvoice}])

The response returned is 200 , but nothing is happening on the sales order level. I think its the way that I defined the field that might be incorrect.

Can someone help with this issue ? Thanks in advance

Upvotes: 0

Views: 1250

Answers (1)

apexprogramming
apexprogramming

Reputation: 433

Nothing is happening on the sales order level because you are not creating a sales record, writing to it without doing anything. Not sure if this would work in your specific case but here is what I would do.

Use the Pro-forma invoice https://www.odoo.com/documentation/user/13.0/sales/invoicing/proforma.html

Then when a sales record is created run the "Send pro-forma invoice" method using the web api. This takes care of the db linking, as it can get very complicated.

Upvotes: 0

Related Questions