From 816f386161f8903d000ffcce0b45de046e02d678 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Tue, 28 Aug 2018 09:53:01 +0200 Subject: [PATCH] [FIX] mail: action send mail no default_type Have a send email automated action on invoices upon validation (write) Go onto the credit notes, create one, and validate Before this commit, at the creation of the attachment (the invoice pdf), there was a traceback because default_type was in the context containing 'out_refund' And that attachments also have a field 'type' So the default_get of the latter got a value that wasn't correct for its field After this commit, we clean the context of the default_type context key since it is irrelevant beyond that point OPW 1868638 closes #26621 --- addons/mail/models/ir_actions.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/addons/mail/models/ir_actions.py b/addons/mail/models/ir_actions.py index a8faa2703b8..12c04b38626 100644 --- a/addons/mail/models/ir_actions.py +++ b/addons/mail/models/ir_actions.py @@ -48,7 +48,11 @@ class ServerActions(models.Model): # TDE CLEANME: when going to new api with server action, remove action if not action.template_id or not self._context.get('active_id'): return False - action.template_id.send_mail(self._context.get('active_id'), force_send=False, raise_exception=False) + # Clean context from default_type to avoid making attachment + # with wrong values in subsequent operations + cleaned_ctx = dict(self.env.context) + cleaned_ctx.pop('default_type', None) + action.template_id.with_context(cleaned_ctx).send_mail(self._context.get('active_id'), force_send=False, raise_exception=False) return False @api.model