From 2971dc0a98bd263f06f79702700d32e5c1b87a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Tue, 13 Sep 2022 10:45:21 +0000 Subject: [PATCH] [FIX] sale: fix usage of message_post_with_template in batch Sending confirmation email is generally done on a singleton recordset but some calls could end up calling in batch. Anyway better safe than sorry. Task-2710804 (Mail: Clean MailThread API) closes odoo/odoo#100137 Related: odoo/enterprise#31301 Signed-off-by: Thibault Delavallee (tde) --- addons/sale/models/sale_order.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/sale/models/sale_order.py b/addons/sale/models/sale_order.py index a90e4c91acf..38ef1d41977 100644 --- a/addons/sale/models/sale_order.py +++ b/addons/sale/models/sale_order.py @@ -832,9 +832,11 @@ class SaleOrder(models.Model): # sending mail in sudo was meant for it being sent from superuser self = self.with_user(SUPERUSER_ID) - mail_template = self._get_confirmation_template() - if mail_template: - self.with_context(force_send=True).message_post_with_template( + for sale_order in self: + mail_template = sale_order._get_confirmation_template() + if not mail_template: + continue + sale_order.with_context(force_send=True).message_post_with_template( mail_template.id, composition_mode='comment', email_layout_xmlid='mail.mail_notification_layout_with_responsible_signature',