<commit_before>from odoo import models, _
from odoo.exceptions import UserError


class ValidateAccountMove(models.TransientModel):
    _inherit = "validate.account.move"

    def validate_move(self):
        if self._context.get('active_model') == 'account.move':
            domain = [('id', 'in', self._context.get('active_ids', [])), ('state', '=', 'draft')]
        elif self._context.get('active_model') == 'account.journal':
            domain = [('journal_id', '=', self._context.get('active_id')), ('state', '=', 'draft')]
        else:
            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 because super method
        # calls "_post" instead of action_post
        moves.action_send_invoice_mail()
        return res<commit_msg>[FIX] account_validate_account_move: send mail on validated invoices.<commit_after>from odoo import models, _
from odoo.exceptions import UserError


class ValidateAccountMove(models.TransientModel):
    _inherit = "validate.account.move"

    def validate_move(self):
        if self._context.get('active_model') == 'account.move':
            domain = [('id', 'in', self._context.get('active_ids', [])), ('state', '=', 'draft')]
        elif self._context.get('active_model') == 'account.journal':
            domain = [('journal_id', '=', self._context.get('active_id')), ('state', '=', 'draft')]
        else:
            raise UserError(_("Missing 'active_model' in context."))

        moves = self.env['account.move'].search(domain).filtered('line_ids')
        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')
{'fraction_non_alphanumeric': 0.13960749330954506, 'fraction_numerical': 0.0, 'mean_word_length': 3.2561669829222013, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '820773', 'n_tokens_mistral': 663, 'n_tokens_neox': 647, 'n_words': 139}