Files
enterprise-addons/data_cleaning/models/data_merge_rule.py
T

37 lines
1.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class Data_MergeRule(models.Model):
_name = 'data_merge.rule'
_description = 'Deduplication Rule'
_order = 'sequence, field_id'
model_id = fields.Many2one('data_merge.model', string='Deduplication Model', ondelete='cascade', required=True, index=True)
res_model_id = fields.Many2one(related='model_id.res_model_id', readonly=True, store=True)
field_id = fields.Many2one('ir.model.fields', string='Unique ID Field',
domain="[('model_id', '=', res_model_id), ('ttype', 'in', ('char', 'text', 'many2one')), ('store', '=', True)]",
required=True, ondelete='cascade')
match_mode = fields.Selection(
lambda self: self._available_match_modes(),
default='exact', string='Merge If', required=True)
sequence = fields.Integer(string='Sequence', default=1)
_uniq_model_id_field_id = models.Constraint(
'unique(model_id, field_id)',
"A field can only appear once!",
)
def _available_match_modes(self):
modes = [('exact', self.env._("Exact Match"))]
# can't conditionally set demo data...
if self.env.context.get('install_mode') or self.env.registry.has_unaccent:
modes.append(('accent', self.env._("Case/Accent Insensitive Match")))
return modes
def _update_default_rules(self):
if self.env.registry.has_unaccent:
self.match_mode = 'accent'