diff --git a/account_ux/wizards/account_validate_account_move.py b/account_ux/wizards/account_validate_account_move.py index 311d6a12b..9df1bd6c5 100644 --- a/account_ux/wizards/account_validate_account_move.py +++ b/account_ux/wizards/account_validate_account_move.py @@ -14,7 +14,15 @@ def validate_move(self): raise UserError(_("Missing 'active_model' in context.")) moves = self.env['account.move'].search(domain).filtered('line_ids') - res = super().validate_move() - # we try to send by email the invoices recently validated - moves.action_send_invoice_mail() + try: + res = super().validate_move() + moves.with_context(mail_notify_force_send=False).action_send_invoice_mail() + except Exception as exp: + # we try to send by email the invoices recently validated + posted_moves = self.filter_posted_moves(moves) + posted_moves.with_context(mail_notify_force_send=False).action_send_invoice_mail() + raise exp return res + + def filter_posted_moves(self, moves): + return moves.filtered(lambda x: x.state == 'posted')