Browse Source

Merge PR #1354 into 14.0

Signed-off-by rafaelbn
14.0
OCA-git-bot 2 years ago
parent
commit
e67a79b7c0
  1. 0
      partner_mobile_unique/README.rst
  2. 1
      partner_mobile_unique/__init__.py
  3. 17
      partner_mobile_unique/__manifest__.py
  4. 3
      partner_mobile_unique/models/__init__.py
  5. 13
      partner_mobile_unique/models/res_company.py
  6. 10
      partner_mobile_unique/models/res_config_settings.py
  7. 39
      partner_mobile_unique/models/res_partner.py
  8. 3
      partner_mobile_unique/readme/CONFIGURE.rst
  9. 1
      partner_mobile_unique/readme/CONTRIBUTORS.rst
  10. 9
      partner_mobile_unique/readme/DESCRIPTION.rst
  11. 1
      partner_mobile_unique/readme/USAGE.rst
  12. BIN
      partner_mobile_unique/static/description/icon.png
  13. BIN
      partner_mobile_unique/static/description/partner_duplicate_error.png
  14. 3
      partner_mobile_unique/tests/__init__.py
  15. 25
      partner_mobile_unique/tests/test_mobile_check_unique.py
  16. 35
      partner_mobile_unique/views/res_config_settings_view.xml
  17. 1
      setup/partner_mobile_unique/odoo/addons/partner_mobile_unique
  18. 6
      setup/partner_mobile_unique/setup.py

0
partner_mobile_unique/README.rst

1
partner_mobile_unique/__init__.py

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

17
partner_mobile_unique/__manifest__.py

@ -0,0 +1,17 @@
# Copyright 2020 Ashish (Ooops) <https://ooops404.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Partner Mobile Format and Duplicate Checker",
"version": "14.0.1.0.0",
"summary": "Restriction on partner creation if another partner has the same mobile",
"author": "Ashish Hirpara, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/partner-contact",
"category": "Partner Management",
"depends": ["base_setup", "phone_validation"],
"license": "AGPL-3",
"maintainers": ["AshishHirapara"],
"installable": True,
"application": False,
"data": ["views/res_config_settings_view.xml"],
}

3
partner_mobile_unique/models/__init__.py

@ -0,0 +1,3 @@
from . import res_config_settings
from . import res_company
from . import res_partner

13
partner_mobile_unique/models/res_company.py

@ -0,0 +1,13 @@
# Copyright 2022 Ooops, Ashish Hirpara
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models
class ResCompany(models.Model):
_inherit = "res.company"
partner_mobile_unique_filter_duplicates = fields.Boolean(
string="Filter duplicate partner moblie number",
help="Don't allow multiple partners to have the same moblie number.",
)

10
partner_mobile_unique/models/res_config_settings.py

@ -0,0 +1,10 @@
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"
partner_mobile_unique_filter_duplicates = fields.Boolean(
related="company_id.partner_mobile_unique_filter_duplicates",
readonly=False,
)

39
partner_mobile_unique/models/res_partner.py

@ -0,0 +1,39 @@
# Copyright 2022 Ooops Ashish Hirpara <https://ooops404.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging
from odoo import _, api, models
from odoo.exceptions import UserError
_logger = logging.getLogger(__name__)
class ResPartner(models.Model):
_inherit = "res.partner"
@api.constrains("mobile")
def _check_mobile_unique(self):
if self.env.company.partner_mobile_unique_filter_duplicates:
for partner in self:
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 += [
("id", "!=", partner.id),
]
if self.search(domain):
raise UserError(
_(
"The mobile number is already exists for another partner."
" This is not supported when duplicate mobile numbers are "
"not allowed."
)
)

3
partner_mobile_unique/readme/CONFIGURE.rst

@ -0,0 +1,3 @@
To not allow multiple partners to have the same mobile, go to "General Settings" and use the
"Filter duplicate partner mobile number"/``partner_mobile_unique_filter_duplicates``
setting.

1
partner_mobile_unique/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Ooops - Ashish Hirpara <ashish.hirapara1995@gmail.com>

9
partner_mobile_unique/readme/DESCRIPTION.rst

@ -0,0 +1,9 @@
This module validates the field ``mobile`` in the model
``res.partner`` for duplication.
As part of the validation, this module throws error on the partner form view if another partner has the same mobile (Optionally).
.. figure:: ../static/description/partner_duplicate_error.png
:alt: Error on partner form
This module has a twin brother named **partner_email_check** which restricts the partner creation when another partner has the same email.

1
partner_mobile_unique/readme/USAGE.rst

@ -0,0 +1 @@
If configured, this module integrate automatically in all of the view ``res.partner``

BIN
partner_mobile_unique/static/description/icon.png

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

BIN
partner_mobile_unique/static/description/partner_duplicate_error.png

After

Width: 1060  |  Height: 532  |  Size: 60 KiB

3
partner_mobile_unique/tests/__init__.py

@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from . import test_mobile_check_unique

25
partner_mobile_unique/tests/test_mobile_check_unique.py

@ -0,0 +1,25 @@
from odoo.exceptions import UserError
from odoo.tests import common
class TestMobileCheckUnique(common.TransactionCase):
def _create_partners(self, name, mobile, company_id=False):
return self.env["res.partner"].create(
{
"name": name,
"mobile": mobile,
"company_id": company_id,
}
)
def test_01_partner_mobile_unique(self):
# create partners
self.env.company.write({"partner_mobile_unique_filter_duplicates": True})
with self.assertRaises(UserError):
self._create_partners("Test Partner 1", "12345678")
self._create_partners("Test Partner 2", "12345678")
with self.assertRaises(UserError):
self._create_partners("Test Partner 4", "12345678", self.env.company.id)

35
partner_mobile_unique/views/res_config_settings_view.xml

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_general_configuration_mobile_check_unique" model="ir.ui.view">
<field name="name">partner_mobile_unique</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base_setup.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@id='companies']" position='after'>
<h2>Mobile validation</h2>
<div class="row mt16 o_settings_container" name="partner_mobile_unique">
<div class="col-xs-12 col-md-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="partner_mobile_unique_filter_duplicates" />
</div>
<div class="o_setting_right_pane">
<label for="partner_mobile_unique_filter_duplicates" />
<span
class="fa fa-lg fa-building-o"
title="Values set here are company-specific."
aria-label="Values set here are company-specific."
groups="base.group_multi_company"
role="img"
/>
<div class="text-muted">
Require partner mobile number to be unique
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>

1
setup/partner_mobile_unique/odoo/addons/partner_mobile_unique

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

6
setup/partner_mobile_unique/setup.py

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