<commit_before># -*- coding: utf-8 -*-45.00
# Copyright (C) 2018 Compassion CH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo.tools import append_content_to_html


class MailComposer(models.TransientModel):
    """
    Extend the mail composer so that it can send message to archived partner,
    and put back the selected partner in the claim in case it was not linked.
    """
    _inherit = 'mail.compose.message'

    @api.multi
    def send_mail(self, auto_commit=False):

        unarchived_ids = self.env.context.get('unarchived_partners', [])
        if unarchived_ids:
            unarchived_res = self.env['res.partner'].browse(unarchived_ids)
            unarchived_res.toggle_active()

        res = super(MailComposer, self).send_mail(auto_commit)

        # Re-archive the unarchived recipient.
        if unarchived_ids:
            unarchived_res.toggle_active()

        # Put back selected partner into claim
        if self.env.context.get('claim_no_partner'):
            gen_mail = self.env['mail.mail'].search([
                ('res_id', '=', self.res_id),
                ('model', '=', 'crm.claim')
            ], limit=1)
            self.env['crm.claim'].browse(self.res_id).write({
                'partner_id': gen_mail.recipient_ids[:1].id
            })

        return res

    @api.multi
    def onchange_template_id(self, template_id, composition_mode, model,
                             res_id):
        """
        Append the quote of previous e-mail to the body of the message.
        """
        result = super(MailComposer, self).onchange_template_id(
            template_id, composition_mode, model, res_id
        )
        reply_quote = self.env.context.get('reply_quote')
        if reply_quote:
            result['value']['body'] = append_content_to_html(
                result['value']['body'],
                '<br/><br/>' + reply_quote, plaintext=False)
        return result
<commit_msg>WIP CO-2552<commit_after># -*- coding: utf-8 -*-45.00
# Copyright (C) 2018 Compassion CH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo.tools import append_content_to_html


class MailComposer(models.TransientModel):
    """
    Extend the mail composer so that it can send message to archived partner,
    and put back the selected partner in the claim in case it was not linked.
    """
    _inherit = 'mail.compose.message'

    @api.multi
    def send_mail(self, auto_commit=False):

        unarchived_ids = self.env.context.get('unarchived_partners', [])
        if unarchived_ids:
            unarchived_res = self.env['res.partner'].browse(unarchived_ids)
            unarchived_res.toggle_active()
            self.write({
                'partner_ids': unarchived_ids
            })

        res = super(MailComposer, self).send_mail(auto_commit)

        # Re-archive the unarchived recipient.
        if unarchived_ids:
            unarchived_res.toggle_active()

        # Put back selected partner into claim
        if self.env.context.get('claim_no_partner'):
            gen_mail = self.env['mail.mail'].search([
                ('res_id', '=', self.res_id),
                ('model', '=', 'crm.claim')
            ], limit=1)
            self.env['crm.claim'].browse(self.res_id).write({
                'partner_id': gen_mail.recipient_ids[:1].id
            })

        return res

    @api.multi
    def onchange_template_id(self, template_id, composition_mode, model,
                             res_id):
        """
        Append the quote of previous e-mail to the body of the message.
        """
        result = super(MailComposer, self).onchange_template_id(
            template_id, composition_mode, model, res_id
        )
        reply_quote = self.env.context.get('reply_quote')
        if reply_quote:
            result['value']['body'] = append_content_to_html(
                result['value']['body'],
                '<br/><br/>' + reply_quote, plaintext=False)
        return result

{'fraction_non_alphanumeric': 0.11500735654732712, 'fraction_numerical': 0.007356547327121138, 'mean_word_length': 2.242448330683625, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '6529017', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1213, 'n_words': 272}