diff --git a/partner_deduplicate_filter/README.rst b/partner_deduplicate_filter/README.rst new file mode 100644 index 000000000..6aa5c85f8 --- /dev/null +++ b/partner_deduplicate_filter/README.rst @@ -0,0 +1,65 @@ +.. 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 + +=========================================== +Exclude some records from the deduplication +=========================================== + +This module extends the possibilities of the contact deduplication allowing +to filter the applicable set according to several criteria. + +For now, only the filter for restricting the deduplication to only companies or +only contacts is implemented. + +Usage +===== + +To use this module, you need to: + +#. Go to *Sales > Tools > Deduplicate Contacts*. +#. Mark "'Is a company?' field selected", "Parent company not set" or + "Parent company set (Contacts)" in the section 'Exclude contacts having'. +#. This criteria will be used for excluding in the deduplication the selected + kind of records. + +.. 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/8.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 +------ + +* `Funnel `_. +* `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_filter/__init__.py b/partner_deduplicate_filter/__init__.py new file mode 100644 index 000000000..f8944f05c --- /dev/null +++ b/partner_deduplicate_filter/__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_filter/__openerp__.py b/partner_deduplicate_filter/__openerp__.py new file mode 100644 index 000000000..d7c531952 --- /dev/null +++ b/partner_deduplicate_filter/__openerp__.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Exclude records from the deduplication", + "version": "8.0.1.0.0", + "category": "Tools", + "website": "https://www.tecnativa.com", + "author": "Tecnativa, " + "Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": [ + "crm", + ], + "data": [ + 'wizards/partner_merge_view.xml', + ], +} diff --git a/partner_deduplicate_filter/i18n/es.po b/partner_deduplicate_filter/i18n/es.po new file mode 100644 index 000000000..7ad3becf5 --- /dev/null +++ b/partner_deduplicate_filter/i18n/es.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_deduplicate_filter +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-08-12 19:57+0000\n" +"PO-Revision-Date: 2016-08-12 19:57+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_filter +#: field:base.partner.merge.automatic.wizard,exclude_is_company:0 +msgid "'Is a company?' field selected" +msgstr "El campo '¿Es una compañía?' seleccionado" + +#. module: crm_deduplicate_filter +#: field:base.partner.merge.automatic.wizard,exclude_parent:0 +msgid "Parent company set (Contacts)" +msgstr "La compañía padre establecida (Contactos)" + +#. module: crm_deduplicate_filter +#: field:base.partner.merge.automatic.wizard,exclude_not_parent:0 +msgid "Parent company not set" +msgstr "La compañía padre no establecida" + diff --git a/partner_deduplicate_filter/i18n/sl.po b/partner_deduplicate_filter/i18n/sl.po new file mode 100644 index 000000000..b5e016439 --- /dev/null +++ b/partner_deduplicate_filter/i18n/sl.po @@ -0,0 +1,34 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * crm_deduplicate_filter +# +# Translators: +# Matjaž Mozetič , 2016 +msgid "" +msgstr "" +"Project-Id-Version: crm (8.0)\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-11-02 14:15+0000\n" +"PO-Revision-Date: 2016-10-21 06:43+0000\n" +"Last-Translator: Matjaž Mozetič \n" +"Language-Team: Slovenian (http://www.transifex.com/oca/OCA-crm-8-0/language/sl/)\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Language: sl\n" +"Plural-Forms: nplurals=4; plural=(n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3);\n" + +#. module: crm_deduplicate_filter +#: field:base.partner.merge.automatic.wizard,exclude_is_company:0 +msgid "'Is a company?' field selected" +msgstr "Polje 'Je pravna oseba' izbrano" + +#. module: crm_deduplicate_filter +#: field:base.partner.merge.automatic.wizard,exclude_not_parent:0 +msgid "Parent company not set" +msgstr "Nadrejena družba ni nastavljena." + +#. module: crm_deduplicate_filter +#: field:base.partner.merge.automatic.wizard,exclude_parent:0 +msgid "Parent company set (Contacts)" +msgstr "Nadrejena družba nastavljena (stiki)" diff --git a/partner_deduplicate_filter/static/description/icon.png b/partner_deduplicate_filter/static/description/icon.png new file mode 100644 index 000000000..49b724769 Binary files /dev/null and b/partner_deduplicate_filter/static/description/icon.png differ diff --git a/partner_deduplicate_filter/static/description/icon.svg b/partner_deduplicate_filter/static/description/icon.svg new file mode 100644 index 000000000..7ba20919f --- /dev/null +++ b/partner_deduplicate_filter/static/description/icon.svg @@ -0,0 +1,102 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + diff --git a/partner_deduplicate_filter/tests/__init__.py b/partner_deduplicate_filter/tests/__init__.py new file mode 100644 index 000000000..4945339d8 --- /dev/null +++ b/partner_deduplicate_filter/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_filter diff --git a/partner_deduplicate_filter/tests/test_crm_deduplicate_filter.py b/partner_deduplicate_filter/tests/test_crm_deduplicate_filter.py new file mode 100644 index 000000000..b6777fa56 --- /dev/null +++ b/partner_deduplicate_filter/tests/test_crm_deduplicate_filter.py @@ -0,0 +1,77 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 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 TestDeduplicateFilter(common.TransactionCase): + def setUp(self): + super(TestDeduplicateFilter, self).setUp() + self.partner_1 = self.env['res.partner'].create({ + 'name': 'Partner 1', + 'email': 'partner1@example.org', + 'is_company': True, + 'parent_id': False, + }) + self.partner_1.copy() + self.partner_2 = self.env['res.partner'].create({ + 'name': 'Partner 2', + 'email': 'partner2@example.org', + 'is_company': False, + 'parent_id': self.partner_1.id, + }) + self.partner_2.copy() + self.partner_3 = self.env['res.partner'].create({ + 'name': 'Partner 3', + 'email': 'partner3@example.org', + 'is_company': False, + 'parent_id': False, + }) + self.partner_3.copy() + self.wizard = self.env['base.partner.merge.automatic.wizard'].create({ + 'group_by_email': True, + }) + + def test_deduplicate_exclude_is_company(self): + self.wizard.exclude_is_company = True + self.wizard.start_process_cb() + matched_founds = 0 + for line in self.wizard.line_ids: + match_ids = safe_eval(line.aggr_ids) + if self.partner_1.id in match_ids: + self.assertTrue(False, 'Partner with is company not excluded') + if self.partner_2.id in match_ids: + matched_founds += 1 + if self.partner_3.id in match_ids: + matched_founds += 1 + self.assertEqual(matched_founds, 2) + + def test_deduplicate_exclude_not_parent(self): + self.wizard.exclude_not_parent = True + self.wizard.start_process_cb() + matched_founds = 0 + for line in self.wizard.line_ids: + match_ids = safe_eval(line.aggr_ids) + if self.partner_1.id in match_ids: + self.assertTrue(False, 'Partner without parent not excluded') + if self.partner_3.id in match_ids: + self.assertTrue(False, 'Partner without parent not excluded') + if self.partner_2.id in match_ids: + matched_founds += 1 + self.assertEqual(matched_founds, 1) + + def test_deduplicate_exclude_parent(self): + self.wizard.exclude_parent = True + self.wizard.start_process_cb() + matched_founds = 0 + for line in self.wizard.line_ids: + match_ids = safe_eval(line.aggr_ids) + if self.partner_2.id in match_ids: + self.assertTrue(False, 'Partner with parent not excluded') + if self.partner_1.id in match_ids: + matched_founds += 1 + if self.partner_3.id in match_ids: + matched_founds += 1 + self.assertEqual(matched_founds, 2) diff --git a/partner_deduplicate_filter/wizards/__init__.py b/partner_deduplicate_filter/wizards/__init__.py new file mode 100644 index 000000000..c93eadfed --- /dev/null +++ b/partner_deduplicate_filter/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_filter/wizards/partner_merge.py b/partner_deduplicate_filter/wizards/partner_merge.py new file mode 100644 index 000000000..26381b791 --- /dev/null +++ b/partner_deduplicate_filter/wizards/partner_merge.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Copyright 2016 Pedro M. Baeza +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import api, fields, models + + +class BasePartnerMergeAutomaticWizard(models.TransientModel): + _inherit = "base.partner.merge.automatic.wizard" + + exclude_is_company = fields.Boolean("'Is a company?' field selected") + exclude_not_parent = fields.Boolean("Parent company not set") + exclude_parent = fields.Boolean("Parent company set (Contacts)") + + @api.multi + def _process_query(self, query): + if any([self.exclude_is_company, self.exclude_not_parent, + self.exclude_parent]): + filters = [] + if self.exclude_is_company: + filters.append("is_company = False") + if self.exclude_not_parent: + filters.append("parent_id IS NOT NULL") + if self.exclude_parent: + filters.append("parent_id IS NULL") + index_where = query.find('WHERE') + index_group_by = query.find('GROUP BY') + subquery = "%s" % ' AND '.join(filters) + if index_where > 0: + subquery = "AND (%s) " % subquery + else: # pragma: no cover + subquery = "WHERE %s " % subquery + query = query[:index_group_by] + subquery + query[index_group_by:] + return super(BasePartnerMergeAutomaticWizard, self)._process_query( + query) diff --git a/partner_deduplicate_filter/wizards/partner_merge_view.xml b/partner_deduplicate_filter/wizards/partner_merge_view.xml new file mode 100644 index 000000000..26d0b5465 --- /dev/null +++ b/partner_deduplicate_filter/wizards/partner_merge_view.xml @@ -0,0 +1,21 @@ + + + + + + + + base.partner.merge.automatic.wizard + + + + + + + + + + + +