diff --git a/partner_deduplicate_by_ref/README.rst b/partner_deduplicate_by_ref/README.rst new file mode 100644 index 000000000..48cda88b1 --- /dev/null +++ b/partner_deduplicate_by_ref/README.rst @@ -0,0 +1,60 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================================= +Deduplicate Contacts by reference +================================= + +This module extends the criteria to match duplicated contacts using the field +reference. + +Usage +===== + +To use this module, you need to: + +#. Go to *Sales > Tools > Deduplicate Contacts*. +#. Mark "Reference" in the section "Search duplicates based on duplicated data + in". +#. This criteria will be used for deduplicating. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/111/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* `Arrow `_. + +Contributors +------------ + +* Pedro M. Baeza + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/partner_deduplicate_by_ref/__init__.py b/partner_deduplicate_by_ref/__init__.py new file mode 100644 index 000000000..f8944f05c --- /dev/null +++ b/partner_deduplicate_by_ref/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import wizards diff --git a/partner_deduplicate_by_ref/__openerp__.py b/partner_deduplicate_by_ref/__openerp__.py new file mode 100644 index 000000000..4c5915ed8 --- /dev/null +++ b/partner_deduplicate_by_ref/__openerp__.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Deduplicate Contacts by reference", + "version": "9.0.1.0.0", + "category": "Tools", + "website": "https://www.tecnativa.com", + "author": "Tecnativa, " + "Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": [ + "crm", + "crm_deduplicate_acl", + ], + "data": [ + 'wizards/partner_merge_view.xml', + ], +} diff --git a/partner_deduplicate_by_ref/i18n/es.po b/partner_deduplicate_by_ref/i18n/es.po new file mode 100644 index 000000000..0defc8aab --- /dev/null +++ b/partner_deduplicate_by_ref/i18n/es.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_deduplicate_by_ref +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 9.0c\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2017-03-01 21:29+0000\n" +"PO-Revision-Date: 2017-03-01 21:29+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: crm_deduplicate_by_ref +#: model:ir.model.fields,field_description:crm_deduplicate_by_ref.field_base_partner_merge_automatic_wizard_group_by_ref +msgid "Reference" +msgstr "Referencia" + +#. module: crm_deduplicate_by_ref +#: model:ir.model,name:crm_deduplicate_by_ref.model_base_partner_merge_automatic_wizard +msgid "base.partner.merge.automatic.wizard" +msgstr "base.partner.merge.automatic.wizard" + diff --git a/partner_deduplicate_by_ref/static/description/icon.png b/partner_deduplicate_by_ref/static/description/icon.png new file mode 100644 index 000000000..82778ec46 Binary files /dev/null and b/partner_deduplicate_by_ref/static/description/icon.png differ diff --git a/partner_deduplicate_by_ref/static/description/icon.svg b/partner_deduplicate_by_ref/static/description/icon.svg new file mode 100644 index 000000000..fc243fd98 --- /dev/null +++ b/partner_deduplicate_by_ref/static/description/icon.svg @@ -0,0 +1,107 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + diff --git a/partner_deduplicate_by_ref/tests/__init__.py b/partner_deduplicate_by_ref/tests/__init__.py new file mode 100644 index 000000000..0e3f4a7d8 --- /dev/null +++ b/partner_deduplicate_by_ref/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import test_crm_deduplicate_by_ref diff --git a/partner_deduplicate_by_ref/tests/test_crm_deduplicate_by_ref.py b/partner_deduplicate_by_ref/tests/test_crm_deduplicate_by_ref.py new file mode 100644 index 000000000..717fb0eeb --- /dev/null +++ b/partner_deduplicate_by_ref/tests/test_crm_deduplicate_by_ref.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp.tests import common +from openerp.tools.safe_eval import safe_eval + + +class TestDeduplicateByRef(common.TransactionCase): + def setUp(self): + super(TestDeduplicateByRef, self).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', + }) + + def test_deduplicate_by_ref(self): + wizard = self.env['base.partner.merge.automatic.wizard'].create({ + 'group_by_ref': True, + }) + wizard.start_process_cb() + 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): + 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.start_process_cb() + 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): + found_match = True + break + self.assertTrue(found_match) diff --git a/partner_deduplicate_by_ref/wizards/__init__.py b/partner_deduplicate_by_ref/wizards/__init__.py new file mode 100644 index 000000000..c93eadfed --- /dev/null +++ b/partner_deduplicate_by_ref/wizards/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2016 Antiun Ingeniería S.L. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import partner_merge diff --git a/partner_deduplicate_by_ref/wizards/partner_merge.py b/partner_deduplicate_by_ref/wizards/partner_merge.py new file mode 100644 index 000000000..e39a9da50 --- /dev/null +++ b/partner_deduplicate_by_ref/wizards/partner_merge.py @@ -0,0 +1,29 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import fields, models + + +class BasePartnerMergeAutomaticWizard(models.TransientModel): + _inherit = "base.partner.merge.automatic.wizard" + + 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(BasePartnerMergeAutomaticWizard, self)._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:]) + return query diff --git a/partner_deduplicate_by_ref/wizards/partner_merge_view.xml b/partner_deduplicate_by_ref/wizards/partner_merge_view.xml new file mode 100644 index 000000000..73f1a1487 --- /dev/null +++ b/partner_deduplicate_by_ref/wizards/partner_merge_view.xml @@ -0,0 +1,20 @@ + + + + + + + base.partner.merge.automatic.wizard + + + + + + + + + + + +