Skip to content

Commit

Permalink
[IMP] Improvements as per #1
Browse files Browse the repository at this point in the history
  • Loading branch information
douglas-tabut authored and ntsirintanis committed Mar 12, 2024
1 parent 5b18031 commit 0cd4394
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions mass_merge/models/base_merge_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class BaseMergeModel(models.Model):

_name = 'base.merge.model'
_description = 'Base Merge Model'

_sql_constraints = [
(
Expand Down
4 changes: 2 additions & 2 deletions mass_merge/models/base_merge_model_lines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
22 changes: 11 additions & 11 deletions mass_merge/models/record_merge_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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),
}))
Expand Down

0 comments on commit 0cd4394

Please sign in to comment.