Browse Source

Merge PR #1161 into 14.0

Signed-off-by rousseldenis
14.0
OCA-git-bot 2 years ago
parent
commit
da1cd4255b
  1. 1
      partner_mobile_duplicate_warn/README.rst
  2. 1
      partner_mobile_duplicate_warn/__init__.py
  3. 23
      partner_mobile_duplicate_warn/__manifest__.py
  4. 1
      partner_mobile_duplicate_warn/models/__init__.py
  5. 40
      partner_mobile_duplicate_warn/models/res_partner.py
  6. 1
      partner_mobile_duplicate_warn/readme/CONFIGURE.rst
  7. 1
      partner_mobile_duplicate_warn/readme/CONTRIBUTORS.rst
  8. 8
      partner_mobile_duplicate_warn/readme/DESCRIPTION.rst
  9. 4
      partner_mobile_duplicate_warn/readme/USAGE.rst
  10. BIN
      partner_mobile_duplicate_warn/static/description/partner_warn_banner.png
  11. 1
      partner_mobile_duplicate_warn/tests/__init__.py
  12. 74
      partner_mobile_duplicate_warn/tests/test_mobile_duplicate.py
  13. 25
      partner_mobile_duplicate_warn/views/res_partner.xml
  14. 1
      requirements.txt
  15. 1
      setup/partner_mobile_duplicate_warn/odoo/addons/partner_mobile_duplicate_warn
  16. 6
      setup/partner_mobile_duplicate_warn/setup.py

1
partner_mobile_duplicate_warn/README.rst

@ -0,0 +1 @@
Will be generated from the README subdir

1
partner_mobile_duplicate_warn/__init__.py

@ -0,0 +1 @@
from . import models

23
partner_mobile_duplicate_warn/__manifest__.py

@ -0,0 +1,23 @@
# Copyright 2021 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Partner Mobile Duplicate Warn",
"version": "14.0.1.0.0",
"category": "Partner Management",
"license": "AGPL-3",
"summary": "Warning banner on partner form if another partner has the same mobile",
"author": "Akretion,Odoo Community Association (OCA)",
"maintainers": ["alexis-via"],
"website": "https://github.com/OCA/partner-contact",
"depends": ["phone_validation"],
# I add phonenumbers in external_dependencies
# because the phone_validation module doesn't do it
# and it's needed for Travis
"external_dependencies": {"python": ["phonenumbers"]},
"data": [
"views/res_partner.xml",
],
"installable": True,
}

1
partner_mobile_duplicate_warn/models/__init__.py

@ -0,0 +1 @@
from . import res_partner

40
partner_mobile_duplicate_warn/models/res_partner.py

@ -0,0 +1,40 @@
# Copyright 2021 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = "res.partner"
same_mobile_partner_id = fields.Many2one(
"res.partner",
compute="_compute_same_mobile_partner_id",
string="Partner with same mobile",
compute_sudo=True,
)
@api.depends("mobile", "company_id")
def _compute_same_mobile_partner_id(self):
# With phone_validation, the "mobile" field should be
# clean in E.164 format, without any start/ending spaces
# So we search on the 'mobile' field with '=' !
for partner in self:
same_mobile_partner_id = False
if partner.mobile:
domain = [("mobile", "=", partner.mobile)]
if partner.company_id:
domain += [
"|",
("company_id", "=", False),
("company_id", "=", partner.company_id.id),
]
partner_id = partner._origin.id
if partner_id:
domain.append(("id", "!=", partner_id))
same_mobile_partner = self.with_context(active_test=False).search(
domain, limit=1
)
same_mobile_partner_id = same_mobile_partner.id or False
partner.same_mobile_partner_id = same_mobile_partner_id

1
partner_mobile_duplicate_warn/readme/CONFIGURE.rst

@ -0,0 +1 @@
No configuration required.

1
partner_mobile_duplicate_warn/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Alexis de Lattre <alexis.delattre@akretion.com>

8
partner_mobile_duplicate_warn/readme/DESCRIPTION.rst

@ -0,0 +1,8 @@
This module adds a warning banner on the partner form view if another partner has the same mobile phone number. It helps spot duplicate partners. If the duplication is confirmed, the user can then use the native partner merge wizard available from the partner tree view (menu *Action > Merge*).
.. figure:: static/description/partner_warn_banner.png
:alt: Warning banner on partner form
This module depend on the module *phone_validation* from the official addons which handle the automatic reformatting of phone numbers to the E.164 format depending on the country of the partner. For exemple, for a French partner, if you write **06.23.45.67.78** in the *Mobile* field, it will be automatically reformatted to **+33 6 23 45 67 78** (via the onchange). Thanks to this reformatting, this module can easily find identical phone numbers on other partners.
It is similar to the native warning banner when another partner has the same VAT number. This module has a twin brother named **partner_email_duplicate_warn** which adds a warning banner when another partner has the same email.

4
partner_mobile_duplicate_warn/readme/USAGE.rst

@ -0,0 +1,4 @@
The warning banner is displayed on the partner form view if another partner:
- has the same mobile phone number (the module *phone_validation* ensure that phone numbers are automatically formatted to the E.164 format),
- if the partner is attached to a specific company: is in the same company or is not attached to a specific company,
- if the partner is not attached to a specific company: is in any company or not attached to a specific company.

BIN
partner_mobile_duplicate_warn/static/description/partner_warn_banner.png

After

Width: 774  |  Height: 603  |  Size: 75 KiB

1
partner_mobile_duplicate_warn/tests/__init__.py

@ -0,0 +1 @@
from . import test_mobile_duplicate

74
partner_mobile_duplicate_warn/tests/test_mobile_duplicate.py

@ -0,0 +1,74 @@
# Copyright 2021 Akretion France (http://www.akretion.com/)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo.tests import tagged
from odoo.tests.common import TransactionCase
@tagged("post_install", "-at_install")
class TestResPartner(TransactionCase):
def setUp(self):
super().setUp()
self.fr_country_id = self.env.ref("base.fr").id
self.partner_simple = self.env["res.partner"].create(
{
"name": "Alexia Payet",
"mobile": " +33699887766 ",
"country_id": self.fr_country_id,
}
)
self.partner_simple._onchange_mobile_validation()
self.company1_id = self.env.ref("base.main_company").id
partner_company = self.env["res.partner"].create(
{
"name": "Test Company",
"is_company": True,
"country_id": self.env.ref("base.fr").id,
}
)
self.company2_id = (
self.env["res.company"]
.create(
{
"name": "Test Company",
"partner_id": partner_company.id,
"currency_id": self.env.ref("base.EUR").id,
}
)
.id
)
def test_partner_duplicate_simple(self):
partner1 = self.env["res.partner"].create(
{
"name": "Test regular",
"mobile": "06 99 88 77 65",
"country_id": self.fr_country_id,
}
)
partner1._onchange_mobile_validation()
self.assertFalse(partner1.same_mobile_partner_id)
partner1.write({"mobile": " 06 99 88 77 66"})
partner1._onchange_mobile_validation()
self.assertEqual(partner1.same_mobile_partner_id, self.partner_simple)
def test_partner_duplicate_multi_company(self):
partner_company1 = self.env["res.partner"].create(
{
"name": "Toto",
"mobile": "+33 6 11 22 33 44",
"company_id": self.company1_id,
}
)
partner_company2 = self.env["res.partner"].create(
{
"name": "Toto",
"mobile": "+33 6 11 22 33 44",
"company_id": self.company2_id,
}
)
self.assertFalse(partner_company1.same_mobile_partner_id)
self.assertFalse(partner_company2.same_mobile_partner_id)
partner_company2.write({"company_id": False})
self.assertEqual(partner_company2.same_mobile_partner_id, partner_company1)

25
partner_mobile_duplicate_warn/views/res_partner.xml

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_partner_form" model="ir.ui.view">
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<div
attrs="{'invisible': [('same_vat_partner_id', '=', False)]}"
position="after"
>
<div
class="alert alert-warning"
role="alert"
attrs="{'invisible': [('same_mobile_partner_id', '=', False)]}"
>
Duplicate warning: partner <field
name="same_mobile_partner_id"
/> has the same <b>Mobile</b>.
</div>
</div>
</field>
</record>
</odoo>

1
requirements.txt

@ -1,2 +1,3 @@
# generated from manifests external_dependencies # generated from manifests external_dependencies
email-validator email-validator
phonenumbers

1
setup/partner_mobile_duplicate_warn/odoo/addons/partner_mobile_duplicate_warn

@ -0,0 +1 @@
../../../../partner_mobile_duplicate_warn

6
setup/partner_mobile_duplicate_warn/setup.py

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading…
Cancel
Save