Browse Source

[ADD]Search Partner by Phone & Mobile & Email

pull/618/head
Nikul Chaudhary 6 years ago
parent
commit
67f239ce08
  1. 48
      partner_phone_search/README.rst
  2. 3
      partner_phone_search/__init__.py
  3. 19
      partner_phone_search/__manifest__.py
  4. 3
      partner_phone_search/models/__init__.py
  5. 28
      partner_phone_search/models/res_partner.py
  6. 3
      partner_phone_search/tests/__init__.py
  7. 27
      partner_phone_search/tests/test_partner.py

48
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
<https://github.com/OCA/partner-contact/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. <support@serpentcs.com>
* Nikul Chaudhary <nikul.chaudhary.serpentcs@gmail.com>
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.

3
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

19
partner_phone_search/__manifest__.py

@ -0,0 +1,19 @@
# Copyright 2018 - TODAY Serpent Consulting Services Pvt. Ltd.
# (<http://www.serpentcs.com>)
# 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,
}

3
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

28
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

3
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

27
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]))
Loading…
Cancel
Save