Hello all,
here's the problem I can't solve.
I'm building an API integration module that will allow Odoo 16 (enterprise) to handle
invoices triggered in an external web shop. So I'm trying to programmatically
create an invoice, that's fully confirmed, sent and printed, and its PDF
would be available from external website.
This is how I create it:
- create an invoice with f.e.:
invoice = request.env['account.move'].create({...})
- create lines with
request.env['account.move.line'].create({...})
- call
invoice._post()
to make it confirmed.
Then invoice number is returned to the external shop.
This is how I send PDF:
stream = pdf.to_pdf_stream(invoice.message_main_attachment_id) [...] return stream.getvalue()
The problem is - how to programmatically make message_main_attachment_id available for the invoice? When doing it via WebUI user has to click "Send & Print", configure stuff in dialog box, then confirm - which creates via RPC account.invoice.send object and then generates a PDF available as attachment. I would like to know how this can be done in code, without enduser's actions.
Thanks for any suggestions.