From 074e8f1be28a20c84ec0d571c442817f76e344c3 Mon Sep 17 00:00:00 2001 From: Kevin Khao Date: Tue, 26 Nov 2019 18:53:49 +0100 Subject: [PATCH] [IMP] partner_deduplicate_by_website: black, isort --- .../__manifest__.py | 11 +-- .../tests/test_crm_deduplicate_by_website.py | 71 +++++++++++-------- .../wizards/partner_merge.py | 21 +++--- 3 files changed, 55 insertions(+), 48 deletions(-) diff --git a/partner_deduplicate_by_website/__manifest__.py b/partner_deduplicate_by_website/__manifest__.py index d0fd4ca21..78f9dc343 100644 --- a/partner_deduplicate_by_website/__manifest__.py +++ b/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"], } diff --git a/partner_deduplicate_by_website/tests/test_crm_deduplicate_by_website.py b/partner_deduplicate_by_website/tests/test_crm_deduplicate_by_website.py index 6081892c2..b944aeddc 100644 --- a/partner_deduplicate_by_website/tests/test_crm_deduplicate_by_website.py +++ b/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) diff --git a/partner_deduplicate_by_website/wizards/partner_merge.py b/partner_deduplicate_by_website/wizards/partner_merge.py index 90b2e6499..4cc49ef21 100644 --- a/partner_deduplicate_by_website/wizards/partner_merge.py +++ b/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