From 0cd43941f771d9c90e2262d7daef2e3ca243d81b Mon Sep 17 00:00:00 2001 From: douglas-tabut Date: Thu, 12 May 2022 02:03:50 +0300 Subject: [PATCH] [IMP] Improvements as per https://github.com/sunflowerit/server-ux/pull/1 --- mass_merge/models/base_merge_model.py | 1 + mass_merge/models/base_merge_model_lines.py | 4 ++-- mass_merge/models/record_merge_criteria.py | 22 ++++++++++----------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/mass_merge/models/base_merge_model.py b/mass_merge/models/base_merge_model.py index 077eaaadde..91a75bb1f2 100644 --- a/mass_merge/models/base_merge_model.py +++ b/mass_merge/models/base_merge_model.py @@ -10,6 +10,7 @@ class BaseMergeModel(models.Model): _name = 'base.merge.model' + _description = 'Base Merge Model' _sql_constraints = [ ( diff --git a/mass_merge/models/base_merge_model_lines.py b/mass_merge/models/base_merge_model_lines.py index d02416b077..5a85417bda 100644 --- a/mass_merge/models/base_merge_model_lines.py +++ b/mass_merge/models/base_merge_model_lines.py @@ -7,9 +7,9 @@ class BaseMergeModelLine(models.Model): _name = 'base.merge.model.line' + _description = 'Base Merge Model Line' - merge_model_id = fields.Many2one( - required=True) + merge_model_id = fields.Many2one('base.merge.model', required=True) field_id = fields.Many2one( comodel_name='ir.model.fields', ondelete='cascade', diff --git a/mass_merge/models/record_merge_criteria.py b/mass_merge/models/record_merge_criteria.py index a2d765c118..0ad9bf8815 100644 --- a/mass_merge/models/record_merge_criteria.py +++ b/mass_merge/models/record_merge_criteria.py @@ -54,30 +54,30 @@ def fill_group(self): fills up the merge groups :return: """ - for merge in self.filtered(lambda m: m.state=='progress'): + for merge in self.filtered(lambda m: m.state == 'progress'): model_id = merge.model_id model_obj = self.env[model_id.model] records = merge.get_records_to_merge() group_dict = {} for r in records: - key = eval(merge.key,{'o': r}) + key = eval(merge.key, {'o': r}) group_dict.setdefault(key, []).append(r.id) merge.group_ids.unlink() lines = [] for ids in group_dict.values(): - if len(ids)>1: + if len(ids) > 1: destiny_record = model_obj.search( [('id', 'in', ids)], order=merge.order or model_obj._order, limit=1 ) - lines.append( (0, 0, { - 'record_id': destiny_record.id, - 'line_ids': [ (0, 0, { - 'record_id': x - }) for x in ids] - }) - ) + lines.append((0, 0, { + 'record_id': destiny_record.id, + 'line_ids': [(0, 0, { + 'record_id': x + }) for x in ids] + }) + ) merge.group_ids = lines def create_merges(self): @@ -95,7 +95,7 @@ def create_merges(self): for group in merge.group_ids.filtered(lambda g: g.to_merge): lines = [] for l in group.line_ids: - lines.append( (0, 0, { + lines.append((0, 0, { 'record_id': l.record_id, 'destiny': (l.record_id == group.record_id), }))