<commit_before># -*- coding: utf-8 -*-
# © 2016 <NAME>. - <NAME>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, api, _
from openerp.exceptions import ValidationError


class ResPartner(models.Model):
    _inherit = "res.partner"

    @api.multi
    @api.constrains('ref', 'is_company', 'company_id')
    def _check_ref(self):
        for partner in self:
            mode = partner.company_id.partner_ref_unique
            if (partner.ref and (
                    mode == 'all' or
                    (mode == 'companies' and partner.is_company))):
                domain = [
                    ('id', '!=', partner.id),
                    ('ref', '=', partner.ref),
                    ('customer', '=', True),
                ]
                if mode == 'companies':
                    domain.append(('is_company', '=', True))
                other = self.search(domain)
                if other:
                    raise ValidationError(
                        _("This reference is equal to partner '%s'") %
                        other[0].display_name)<commit_msg>Work with contact deduplicator.<commit_after># -*- coding: utf-8 -*-
# © 2016 <NAME>. - <NAME>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from openerp import models, api, _
from openerp.exceptions import ValidationError


class ResPartner(models.Model):
    _inherit = "res.partner"

    @api.multi
    @api.constrains('ref', 'is_company', 'company_id')
    def _check_ref(self):
        for partner in self:
            mode = partner.company_id.partner_ref_unique
            if (partner.ref and (
                    mode == 'all' or
                    (mode == 'companies' and partner.is_company))):
                domain = [
                    ('id', '!=', partner.id),
                    ('ref', '=', partner.ref),
                    ('customer', '=', True),
                ]
                if mode == 'companies':
                    domain.append(('is_company', '=', True))
                other = self.search(domain)

                # active_test is False when called from
                # base.partner.merge.automatic.wizard
                if other and self.env.context.get("active_test", True):
                    raise ValidationError(
                        _("This reference is equal to partner '%s'") %
                        other[0].display_name)
{'fraction_non_alphanumeric': 0.13286713286713286, 'fraction_numerical': 0.00658165364047717, 'mean_word_length': 1.5735449735449736, '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': '810296', 'n_tokens_mistral': 712, 'n_tokens_neox': 651, 'n_words': 158}