From 67f239ce08729c0f48e9bd03df35976e180a16d2 Mon Sep 17 00:00:00 2001 From: Nikul Chaudhary Date: Tue, 21 Aug 2018 15:34:09 +0530 Subject: [PATCH] [ADD]Search Partner by Phone & Mobile & Email --- partner_phone_search/README.rst | 48 ++++++++++++++++++++++ partner_phone_search/__init__.py | 3 ++ partner_phone_search/__manifest__.py | 19 +++++++++ partner_phone_search/models/__init__.py | 3 ++ partner_phone_search/models/res_partner.py | 28 +++++++++++++ partner_phone_search/tests/__init__.py | 3 ++ partner_phone_search/tests/test_partner.py | 27 ++++++++++++ 7 files changed, 131 insertions(+) create mode 100644 partner_phone_search/README.rst create mode 100644 partner_phone_search/__init__.py create mode 100644 partner_phone_search/__manifest__.py create mode 100644 partner_phone_search/models/__init__.py create mode 100644 partner_phone_search/models/res_partner.py create mode 100644 partner_phone_search/tests/__init__.py create mode 100644 partner_phone_search/tests/test_partner.py diff --git a/partner_phone_search/README.rst b/partner_phone_search/README.rst new file mode 100644 index 000000000..926881d0a --- /dev/null +++ b/partner_phone_search/README.rst @@ -0,0 +1,48 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: https://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +================================= +Search Partner Phone/Mobile/Email +================================= + +This module search a partner email and phone & mobile number. + +Usage +===== + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/134/11.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 +======= + +Contributors +------------ + +* Serpent Consulting Services Pvt. Ltd. +* Nikul Chaudhary + +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_phone_search/__init__.py b/partner_phone_search/__init__.py new file mode 100644 index 000000000..4b76c7b2d --- /dev/null +++ b/partner_phone_search/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/partner_phone_search/__manifest__.py b/partner_phone_search/__manifest__.py new file mode 100644 index 000000000..79977c6ad --- /dev/null +++ b/partner_phone_search/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2018 - TODAY Serpent Consulting Services Pvt. Ltd. +# () +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +{ + 'name': 'Search Partner Phone/Mobile/Email', + 'version': '11.0.1.0.0', + 'category': 'Extra Tools', + 'summary': 'Partner Search by Phone/Mobile/Email', + 'author': "Serpent Consulting Services Pvt. Ltd.," + "Odoo Community Association (OCA)", + 'website': 'https://github.com/OCA/partner-contact', + 'license': 'AGPL-3', + 'depends': [ + 'base', + ], + 'installable': True, + 'auto_install': False, +} diff --git a/partner_phone_search/models/__init__.py b/partner_phone_search/models/__init__.py new file mode 100644 index 000000000..284a83ff1 --- /dev/null +++ b/partner_phone_search/models/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from . import res_partner diff --git a/partner_phone_search/models/res_partner.py b/partner_phone_search/models/res_partner.py new file mode 100644 index 000000000..5063b6116 --- /dev/null +++ b/partner_phone_search/models/res_partner.py @@ -0,0 +1,28 @@ +# Copyright 2018 - TODAY Serpent Consulting Services Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class ResPartner(models.Model): + _inherit = 'res.partner' + + @api.model + def name_search(self, name, args=None, operator='ilike', limit=100): + if not args: + args = [] + if name: + domain = ['|', '|', ('phone', operator, name), + ('mobile', operator, name), ('email', operator, name) + ] + partners = self.search(domain + args, limit=limit,) + res = partners.name_get() + if limit: + limit_rest = limit - len(partners) + else: + limit_rest = limit + if limit_rest or not limit: + args += [('id', 'not in', partners.ids)] + res += super(ResPartner, self).name_search( + name, args=args, operator=operator, limit=limit_rest) + return res diff --git a/partner_phone_search/tests/__init__.py b/partner_phone_search/tests/__init__.py new file mode 100644 index 000000000..ec062e2de --- /dev/null +++ b/partner_phone_search/tests/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from . import test_partner diff --git a/partner_phone_search/tests/test_partner.py b/partner_phone_search/tests/test_partner.py new file mode 100644 index 000000000..be7e7a6e1 --- /dev/null +++ b/partner_phone_search/tests/test_partner.py @@ -0,0 +1,27 @@ +# Copyright 2018 - TODAY Serpent Consulting Services Pvt. Ltd. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests.common import TransactionCase + + +class TestResPartner(TransactionCase): + + def setUp(self): + super(TestResPartner, self).setUp() + self.PartnerObj = self.env['res.partner'] + self.partner_id = self.PartnerObj.create({ + 'name': 'Serpent', + 'mobile': '1234567890', + 'email': 'abc.serpentcs@gmail.com', + 'customer': True, + 'city': 'india', + }) + + def test_name_search(self): + partner_ids = self.PartnerObj.name_search( + name="1234567890", + operator='ilike', + args=[('id', 'in', self.partner_id.ids)] + ) + self.assertEqual(set([self.partner_id.id]), + set([a[0] for a in partner_ids]))