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

from email.utils import parseaddr
from odoo import api, models


class CrmClaim(models.Model):
    _inherit = "crm.claim"

    @api.multi
    def write(self, values):
        """
        - Create alias with the e-mail address if a partner is selected.
        """
        super(CrmClaim, self).write(values)
        if values.get('partner_id'):
            partner = self.env['res.partner'].browse(values['partner_id'])
            for request in self:
                email_alias = parseaddr(request.email_from)[1]
                if email_alias != partner.email:
                    partner.with_context(no_upsert=True).copy({
                        'type': 'email_alias',
                        'email': email_alias,
                        'contact_id': partner.id,
                        'active': False,
                    })
        return True
<commit_msg>CO-2491 Don't create alias if there no email<commit_after># -*- coding: utf-8 -*-45.00
# Copyright (C) 2019 Compassion CH
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from email.utils import parseaddr
from odoo import api, models


class CrmClaim(models.Model):
    _inherit = "crm.claim"

    @api.multi
    def write(self, values):
        """
        - Create alias with the e-mail address if a partner is selected.
        """
        super(CrmClaim, self).write(values)
        if values.get('partner_id'):
            partner = self.env['res.partner'].browse(values['partner_id'])
            for request in self:
                email_alias = parseaddr(request.email_from)[1]
                if email_alias and email_alias != partner.email:
                    partner.with_context(no_upsert=True).copy({
                        'type': 'email_alias',
                        'email': email_alias,
                        'contact_id': partner.id,
                        'active': False,
                    })

        return True

{'fraction_non_alphanumeric': 0.11583011583011583, 'fraction_numerical': 0.013513513513513514, 'mean_word_length': 1.7788203753351206, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4917613', 'n_tokens_mistral': 612, 'n_tokens_neox': 577, 'n_words': 145}