|
|
@ -26,72 +26,102 @@ class opendons_duplicate_partner(models.Model): |
|
|
|
|
|
|
|
def find_duplicate_partner(self): |
|
|
|
self.env['opendons.duplicate_partner'].search([]).unlink() |
|
|
|
rules=self.env['opendons.duplicate_rule'].search([('active','=','true')]) |
|
|
|
rules=self.env['opendons.duplicate_rule'].search([('is_active','=','true')]) |
|
|
|
dbl_partner_ids=[] |
|
|
|
|
|
|
|
i=1 |
|
|
|
|
|
|
|
for rule in rules: |
|
|
|
groupby_fields='' |
|
|
|
selected_fields='' |
|
|
|
list_field=[] |
|
|
|
for f in rule.field_ids: |
|
|
|
if i==1:groupby_fields+="'"+f.field+"'" |
|
|
|
else:groupby_fields+=",'"+f.field+"'" |
|
|
|
list_field.append(f.field) |
|
|
|
i=i+1 |
|
|
|
selected_fields='' |
|
|
|
j=1 |
|
|
|
i=i-1 |
|
|
|
for f in list_field: |
|
|
|
if j==1:selected_fields+=""+f+"" |
|
|
|
if j>1 and j<i:selected_fields+="'"+f+"" |
|
|
|
if j==i and j!=1:selected_fields+=","+f+"" |
|
|
|
j=j+1 |
|
|
|
j=j-1 |
|
|
|
last_field=list_field[j-1] |
|
|
|
|
|
|
|
sql="select count(id) as __count, "+ selected_fields +" from res_partner group by "+ selected_fields |
|
|
|
self.env.cr.execute(sql) |
|
|
|
|
|
|
|
p=self.env.cr.dictfetchall() |
|
|
|
|
|
|
|
#raise Warning(json.dumps(p)) |
|
|
|
for pp in p: |
|
|
|
|
|
|
|
if int(pp['__count'])>1: |
|
|
|
|
|
|
|
domain='' |
|
|
|
if rule.field_ids: |
|
|
|
groupby_fields='' |
|
|
|
selected_fields='' |
|
|
|
list_field=[] |
|
|
|
for f in rule.field_ids: |
|
|
|
try: |
|
|
|
if i==1:groupby_fields+="'"+f.field+"'" |
|
|
|
else:groupby_fields+=",'"+f.field+"'" |
|
|
|
list_field.append(f.field) |
|
|
|
i=i+1 |
|
|
|
except: |
|
|
|
raise warning(f.field) |
|
|
|
selected_fields='' |
|
|
|
j=1 |
|
|
|
i=i-1 |
|
|
|
for f in list_field: |
|
|
|
try: |
|
|
|
if j==1:selected_fields+=""+f+"" |
|
|
|
if j>1 and j<i:selected_fields+="'"+f+"" |
|
|
|
if j==i and j!=1:selected_fields+=","+f+"" |
|
|
|
j=j+1 |
|
|
|
except: |
|
|
|
raise warning(f.field) |
|
|
|
j=j-1 |
|
|
|
last_field=list_field[j-1] |
|
|
|
|
|
|
|
sql="select count(id) as __count, "+ selected_fields +" from res_partner group by "+ selected_fields |
|
|
|
try: |
|
|
|
self.env.cr.execute(sql) |
|
|
|
|
|
|
|
p=self.env.cr.dictfetchall() |
|
|
|
except: |
|
|
|
raise Warning(sql) |
|
|
|
#raise Warning(json.dumps(p)) |
|
|
|
|
|
|
|
for pp in p: |
|
|
|
|
|
|
|
if len(list_field)>1:domain="['&'," |
|
|
|
else:domain="[" |
|
|
|
|
|
|
|
i=1 |
|
|
|
for f in list_field: |
|
|
|
if pp[f]: |
|
|
|
if i==1:domain+="('"+f+"','=','"+pp[f]+"')" |
|
|
|
if i>1:domain+=",('"+f+"','=','"+pp[f]+"')" |
|
|
|
i=i+1 |
|
|
|
domain+=']' |
|
|
|
if domain!='[]': |
|
|
|
if int(pp['__count'])>1: |
|
|
|
|
|
|
|
partner_dbl=self.env['res.partner'].search(eval(domain)) |
|
|
|
domain='' |
|
|
|
|
|
|
|
for partner in partner_dbl: |
|
|
|
vals={} |
|
|
|
vals['partner_id']=partner.id |
|
|
|
self.env['opendons.duplicate_partner'].create(vals) |
|
|
|
dbl_partner_ids.append(partner.id) |
|
|
|
|
|
|
|
action = self.env.ref("contacts.action_contacts").sudo().read([])[0] |
|
|
|
|
|
|
|
action.update( |
|
|
|
{ |
|
|
|
"domain": [("id", "in", dbl_partner_ids)], |
|
|
|
"limit": 5000, |
|
|
|
"context":{'view_mode':'tree'} |
|
|
|
} |
|
|
|
) |
|
|
|
return action |
|
|
|
if len(list_field)>0: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
i=1 |
|
|
|
for f in list_field: |
|
|
|
|
|
|
|
if pp[f]!='' and pp[f]: |
|
|
|
|
|
|
|
try: |
|
|
|
if i==1:domain+="('"+f+"','=','"+pp[f]+"')" |
|
|
|
if i>1:domain+=",('"+f+"','=','"+pp[f]+"')" |
|
|
|
except: raise Warning(f+' '+pp[f]) |
|
|
|
|
|
|
|
i=i+1 |
|
|
|
if len(list_field)>1 : domain="['&',"+domain+"]" |
|
|
|
else:domain="["+domain+"]" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else:domain="[]" |
|
|
|
|
|
|
|
|
|
|
|
if domain!='[]' and domain!="['&',]" : |
|
|
|
|
|
|
|
try: |
|
|
|
partner_dbl=self.env['res.partner'].search(eval(domain)) |
|
|
|
|
|
|
|
for partner in partner_dbl: |
|
|
|
vals={} |
|
|
|
vals['partner_id']=partner.id |
|
|
|
self.env['opendons.duplicate_partner'].create(vals) |
|
|
|
dbl_partner_ids.append(partner.id) |
|
|
|
except: |
|
|
|
raise Warning(domain) |
|
|
|
|
|
|
|
if dbl_partner_ids: |
|
|
|
action = self.env.ref("contacts.action_contacts").sudo().read([])[0] |
|
|
|
|
|
|
|
action.update( |
|
|
|
{ |
|
|
|
"domain": [("id", "in", dbl_partner_ids)], |
|
|
|
"limit": 5000, |
|
|
|
'view_mode': 'tree', |
|
|
|
'view_type': 'list' |
|
|
|
#"context":{'view_mode':'tree,form'} |
|
|
|
} |
|
|
|
) |
|
|
|
return action |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -104,8 +134,22 @@ class opendons_duplicate_rule(models.Model): |
|
|
|
string='fields', |
|
|
|
|
|
|
|
) |
|
|
|
active=fields.Boolean('active' ,default=True) |
|
|
|
is_active=fields.Boolean('active' ,default=True) |
|
|
|
fields_selected=fields.Char('fields', compute='_fields_selected') |
|
|
|
|
|
|
|
def _fields_selected(self): |
|
|
|
for rec in self: |
|
|
|
result='' |
|
|
|
field_list=rec.field_ids |
|
|
|
if field_list: |
|
|
|
i=1 |
|
|
|
for f in field_list: |
|
|
|
if i==1: result+=f.field |
|
|
|
else:result+=','+f.field |
|
|
|
i=i+1 |
|
|
|
rec.fields_selected=result |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class opendons_duplicate_rule_line(models.Model): |
|
|
@ -140,3 +184,6 @@ class opendons_duplicate_rule_line(models.Model): |
|
|
|
result.append((key,key)) |
|
|
|
raise Warning(result) |
|
|
|
return result |
|
|
|
|
|
|
|
|
|
|
|
|