Browse Source

[IMP] partner_deduplicate_by_ref: black, isort

14.0
Manuel Calero 4 years ago
committed by mariadforgeflow
parent
commit
30c5c72646
  1. 11
      partner_deduplicate_by_ref/__manifest__.py
  2. 35
      partner_deduplicate_by_ref/tests/test_partner_deduplicate_by_ref.py
  3. 19
      partner_deduplicate_by_ref/wizards/partner_merge.py
  4. 16
      partner_deduplicate_by_ref/wizards/partner_merge_view.xml

11
partner_deduplicate_by_ref/__manifest__.py

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

35
partner_deduplicate_by_ref/tests/test_partner_deduplicate_by_ref.py

@ -8,42 +8,35 @@ from odoo.tools.safe_eval import safe_eval
class TestDeduplicateByRef(common.TransactionCase):
def setUp(self):
super().setUp()
self.partner_1 = self.env['res.partner'].create({
'name': 'Partner 1',
'ref': '123456',
'email': 'test@deduplicate.com',
})
self.partner_2 = self.env['res.partner'].create({
'name': 'Partner 2',
'ref': '123456',
'email': 'test@deduplicate.com',
})
self.partner_1 = self.env["res.partner"].create(
{"name": "Partner 1", "ref": "123456", "email": "test@deduplicate.com",}
)
self.partner_2 = self.env["res.partner"].create(
{"name": "Partner 2", "ref": "123456", "email": "test@deduplicate.com",}
)
def test_deduplicate_by_ref(self):
wizard = self.env['base.partner.merge.automatic.wizard'].create({
'group_by_ref': True,
})
wizard = self.env["base.partner.merge.automatic.wizard"].create(
{"group_by_ref": 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_ref_and_is_company(self):
wizard = self.env['base.partner.merge.automatic.wizard'].create({
'group_by_ref': True,
'group_by_email': True,
})
wizard = self.env["base.partner.merge.automatic.wizard"].create(
{"group_by_ref": 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)

19
partner_deduplicate_by_ref/wizards/partner_merge.py

@ -7,22 +7,19 @@ from openerp import fields, models
class BasePartnerMergeAutomaticWizard(models.TransientModel):
_inherit = "base.partner.merge.automatic.wizard"
group_by_ref = fields.Boolean('Reference')
group_by_ref = fields.Boolean("Reference")
def _generate_query(self, fields, maximum_group=100):
"""Inject the additional criteria 'ref IS NOT NULL' when needed.
There's no better way to do it, as there are no hooks for adding
this criteria regularly.
"""
query = super()._generate_query(
fields, maximum_group=maximum_group)
if 'ref' in fields:
if 'WHERE' in query:
index = query.find('WHERE')
query = (query[:index + 6] + "ref IS NOT NULL AND " +
query[index + 6:])
query = super()._generate_query(fields, maximum_group=maximum_group)
if "ref" in fields:
if "WHERE" in query:
index = query.find("WHERE")
query = query[: index + 6] + "ref IS NOT NULL AND " + query[index + 6 :]
else:
index = query.find(' GROUP BY')
query = (query[:index] + " WHERE ref IS NOT NULL" +
query[index:])
index = query.find(" GROUP BY")
query = query[:index] + " WHERE ref IS NOT NULL" + query[index:]
return query

16
partner_deduplicate_by_ref/wizards/partner_merge_view.xml

@ -1,20 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2017 Pedro M. Baeza <pedro.baeza@tecnativa.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
<odoo>
<record id="base_partner_merge_automatic_wizard_form" model="ir.ui.view">
<field name="model">base.partner.merge.automatic.wizard</field>
<field name="inherit_id" ref="base.base_partner_merge_automatic_wizard_form"/>
<field name="inherit_id" ref="base.base_partner_merge_automatic_wizard_form" />
<field name="arch" type="xml">
<field name="group_by_parent_id" position="after">
<field name="group_by_ref"/>
<field name="group_by_ref" />
</field>
<xpath expr="//field[@name='partner_ids']/tree//field[@name='country_id']" position="after">
<field name="ref"/>
<xpath
expr="//field[@name='partner_ids']/tree//field[@name='country_id']"
position="after"
>
<field name="ref" />
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save