I am currently working on sending invoices via email using the Odoo 17 API from a Node.js server. I've managed to handle most of the tasks, but I encountered an issue when trying to send an invoice via email. Instead of being sent as an attachment, the invoice is included as a link in the email.
understand that to attach the invoice as a PDF file, I need to make an API call like this:
{
"jsonrpc": "2.0",
"method": "call",
"params": {
"service": "object",
"method": "execute_kw",
"args": [
"{{db}}",
"{{uid}}",
"{{password}}",
"ir.attachment",
"create",
[{
"name": "Invoice.pdf",
"type": "binary",
"res_model": "account.move",
"datas": "base64 data",
"res_id": 17,
"mimetype": "application/pdf"
}]
]
}
}
But first I need to somehow encode the data into base64 format. Is there an Odoo API method to directly encode the file? Or maybe it's possible that there's a setting in Odoo that could automatically add the invoice as an attachment when it's created, instead of manually handling the attachment via API?
Thanks in advance!
I think I can just use email templates. Then the attachment is being added automatically. The body of the API call is like this:
{ "jsonrpc": "2.0", "method": "call", "params": { "service": "object", "method": "execute_kw", "args": [ "{{db}}", "{{uid}}", "{{password}}", "mail.template", "send_mail", [12, 50], { "force_send": "True" } ] }, "id": 5 }