Browse Source

[IMP] partner_deduplicate_by_website: black, isort

14.0
Kevin Khao 5 years ago
committed by mariadforgeflow
parent
commit
074e8f1be2
  1. 11
      partner_deduplicate_by_website/__manifest__.py
  2. 71
      partner_deduplicate_by_website/tests/test_crm_deduplicate_by_website.py
  3. 21
      partner_deduplicate_by_website/wizards/partner_merge.py

11
partner_deduplicate_by_website/__manifest__.py

@ -8,14 +8,9 @@
"version": "12.0.1.0.0",
"category": "Tools",
"website": "https://github.com/OCA/crm",
"author": "Tecnativa, "
"Odoo Community Association (OCA)",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"license": "AGPL-3",
"installable": True,
"depends": [
"contacts",
],
"data": [
'wizards/partner_merge_view.xml',
],
"depends": ["contacts"],
"data": ["wizards/partner_merge_view.xml"],
}

71
partner_deduplicate_by_website/tests/test_crm_deduplicate_by_website.py

@ -7,54 +7,65 @@ from odoo.tools.safe_eval import safe_eval
class TestDeduplicateByWebsite(common.SavepointCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.partner_1 = cls.env['res.partner'].with_context(
tracking_disable=True).create({
'name': 'Partner 1',
'website': 'www.test-deduplicate.com',
'email': 'test@deduplicate.com',
})
cls.partner_1 = (
cls.env["res.partner"]
.with_context(tracking_disable=True)
.create(
{
"name": "Partner 1",
"website": "www.test-deduplicate.com",
"email": "test@deduplicate.com",
}
)
)
def test_deduplicate_by_website(self):
self.partner_2 = self.env['res.partner'].with_context(
tracking_disable=True).create({
'name': 'Partner 2',
'website': 'www.test-deduplicate.com',
'email': 'test2@deduplicate.com',
})
wizard = self.env['base.partner.merge.automatic.wizard'].create({
'group_by_website': True,
})
self.partner_2 = (
self.env["res.partner"]
.with_context(tracking_disable=True)
.create(
{
"name": "Partner 2",
"website": "www.test-deduplicate.com",
"email": "test2@deduplicate.com",
}
)
)
wizard = self.env["base.partner.merge.automatic.wizard"].create(
{"group_by_website": True}
)
wizard.action_start_manual_process()
found_match = False
for line in wizard.line_ids:
match_ids = safe_eval(line.aggr_ids)
if (self.partner_1.id in match_ids and
self.partner_2.id in match_ids):
if self.partner_1.id in match_ids and self.partner_2.id in match_ids:
found_match = True
break
self.assertTrue(found_match)
def test_deduplicate_by_website_and_is_company(self):
self.partner_2 = self.env['res.partner'].with_context(
tracking_disable=True).create({
'name': 'Partner 2',
'website': 'www.test-deduplicate.com',
'email': 'test@deduplicate.com',
})
wizard = self.env['base.partner.merge.automatic.wizard'].create({
'group_by_website': True,
'group_by_email': True,
})
self.partner_2 = (
self.env["res.partner"]
.with_context(tracking_disable=True)
.create(
{
"name": "Partner 2",
"website": "www.test-deduplicate.com",
"email": "test@deduplicate.com",
}
)
)
wizard = self.env["base.partner.merge.automatic.wizard"].create(
{"group_by_website": True, "group_by_email": True}
)
wizard.action_start_manual_process()
found_match = False
for line in wizard.line_ids:
match_ids = safe_eval(line.aggr_ids)
if (self.partner_1.id in match_ids and
self.partner_2.id in match_ids):
if self.partner_1.id in match_ids and self.partner_2.id in match_ids:
found_match = True
break
self.assertTrue(found_match)

21
partner_deduplicate_by_website/wizards/partner_merge.py

@ -7,7 +7,7 @@ from odoo import fields, models
class BasePartnerMergeAutomaticWizard(models.TransientModel):
_inherit = "base.partner.merge.automatic.wizard"
group_by_website = fields.Boolean('Website')
group_by_website = fields.Boolean("Website")
def _generate_query(self, fields, maximum_group=100):
"""Inject the additional criteria 'website IS NOT NULL' when needed.
@ -15,14 +15,15 @@ class BasePartnerMergeAutomaticWizard(models.TransientModel):
this criteria regularly.
"""
query = super(BasePartnerMergeAutomaticWizard, self)._generate_query(
fields, maximum_group=maximum_group)
if 'website' in fields:
if 'WHERE' in query:
index = query.find('WHERE')
query = (query[:index + 6] + "website IS NOT NULL AND " +
query[index + 6:])
fields, maximum_group=maximum_group
)
if "website" in fields:
if "WHERE" in query:
index = query.find("WHERE")
query = (
query[: index + 6] + "website IS NOT NULL AND " + query[index + 6 :]
)
else:
index = query.find(' GROUP BY')
query = (query[:index] + " WHERE website IS NOT NULL" +
query[index:])
index = query.find(" GROUP BY")
query = query[:index] + " WHERE website IS NOT NULL" + query[index:]
return query
Loading…
Cancel
Save