From 90d23eb3e2e658667b970e143d3a0750e92f2c8a Mon Sep 17 00:00:00 2001 From: dasa-odoo Date: Fri, 23 Jul 2021 11:22:19 +0000 Subject: [PATCH] [IMP] account: only generate email and pdf once on send&print invoice action_invoice_sent() triggers two onchanges which normally don't happen at the same time. Added a check to one of them (onchange_is_email()), so that on action_invoice_sent(), only one of them calls the computationally expensive onchange_template_id_wrapper(), effectively halving the time taken. Time for executing the action for one invoice dropped from over 3 seconds to a bit over 1. closes odoo/odoo#74160 Signed-off-by: Laurent Smet --- addons/account/models/account_move.py | 3 ++- addons/account/wizard/account_invoice_send.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index a1afee941c4..aa529c50835 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -2779,7 +2779,8 @@ class AccountMove(models.Model): mark_invoice_as_sent=True, custom_layout="mail.mail_notification_paynow", model_description=self.with_context(lang=lang).type_name, - force_email=True + force_email=True, + wizard_opened=True ) return { 'name': _('Send Invoice'), diff --git a/addons/account/wizard/account_invoice_send.py b/addons/account/wizard/account_invoice_send.py index 3aa946a77e3..6c9468b9723 100644 --- a/addons/account/wizard/account_invoice_send.py +++ b/addons/account/wizard/account_invoice_send.py @@ -93,7 +93,8 @@ class AccountInvoiceSend(models.TransientModel): self.composer_id.composition_mode = 'comment' if len(res_ids) == 1 else 'mass_mail' self.composer_id.template_id = self.template_id.id self._compute_composition_mode() - self.composer_id.onchange_template_id_wrapper() + if not self.env.context.get("wizard_opened"): + self.composer_id.onchange_template_id_wrapper() @api.onchange('is_email') def _compute_invoice_without_email(self):