Running odoo on vps.
I Try to send mail from validated purchase order using :
sendMail = models.execute_kw(db, uid, password, 'purchase.order', 'action_rfq_send',[orderId],{'context' : {'send_rfq': False}})
models.execute_kw(db, uid, password, 'mail.compose.message', 'action_send_mail',[[sendMail['context']['default_template_id']]])
Mailing is configured and works when triggered manually
First block is a print of the output of the sendMail method
Second block is the output of the xmlrpc action_send_mail that comes after.
I must be missing a parameter in either the sendMail or the action_send_mail but I couldn't find which. I have also tried replacing default_template_id by view_id as such:
models.execute_kw(db, uid, password, 'mail.compose.message', 'action_send_mail',[[sendMail['context']['view_id']]])
Using the mail wizard by xml-rpc is possible, but i wouldn't use it.
But the error is the following. You're trying to use action_send_mail
of the mail wizard, which needs the currents wizard id. But you're giving [sendMail['context']['view_id']]
(or default_template_id
) which is not a wizards ID.
The method action_send_mail
of purchase.order
is returning an action in form of a dictionary. The only key/value pair in an odoo window action dictionary holding an actual ID of the actions underlying model is res_id
and in this case, there is never one in it. That's because Odoo made that method for the browser client...
So what can you do instead? First you should look into action_send_mail
to get what's done there and what values you could use. There are a lot of things for the browser and the wizard. But for xml-rpc only 2 things are really necessary: the order ID and the mail template ID.
You already have the order id, in your example code orderId
. For Odoo 15 there are two mail templates used by the wizard. Let's stick to the one with xml id purchase.email_template_edi_purchase
, which will be used in my example code later on.
You now can use both IDs to send the mail by using the features of Odoo's mail templates.
That following code is for Odoo 15 and probably not working in older versions.
# first get mail template id (either by xml id or you could hardcode it, but that's ugly)
mail_template_xml_id = "purchase.email_template_edi_purchase"
module, xml_id_name = mail_template_xml_id.split(".")
template_model, template_id = models.execute_kw(
db, uid, password, 'ir.model.data',
'check_object_reference',
[module, xml_id_name])
# send the mail by template
models.execute_kw(db, uid, password, template_model,
'send_mail',
[template_id, orderId])