From 39678633f05ea2f0f71ba6292c276cbe0bb14784 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A0n=20Todorovich?= Date: Thu, 12 Nov 2020 18:07:27 -0300 Subject: [PATCH] [ADD] partner_phone_secondary --- partner_phone_secondary/__init__.py | 1 + partner_phone_secondary/__manifest__.py | 15 +++++++++++++++ partner_phone_secondary/models/__init__.py | 1 + partner_phone_secondary/models/res_partner.py | 17 +++++++++++++++++ .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + partner_phone_secondary/tests/__init__.py | 1 + .../tests/test_partner_phone_secondary.py | 19 +++++++++++++++++++ partner_phone_secondary/views/res_partner.xml | 19 +++++++++++++++++++ .../odoo/addons/partner_phone_secondary | 1 + setup/partner_phone_secondary/setup.py | 6 ++++++ 11 files changed, 82 insertions(+) create mode 100644 partner_phone_secondary/__init__.py create mode 100644 partner_phone_secondary/__manifest__.py create mode 100644 partner_phone_secondary/models/__init__.py create mode 100644 partner_phone_secondary/models/res_partner.py create mode 100644 partner_phone_secondary/readme/CONTRIBUTORS.rst create mode 100644 partner_phone_secondary/readme/DESCRIPTION.rst create mode 100644 partner_phone_secondary/tests/__init__.py create mode 100644 partner_phone_secondary/tests/test_partner_phone_secondary.py create mode 100644 partner_phone_secondary/views/res_partner.xml create mode 120000 setup/partner_phone_secondary/odoo/addons/partner_phone_secondary create mode 100644 setup/partner_phone_secondary/setup.py diff --git a/partner_phone_secondary/__init__.py b/partner_phone_secondary/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/partner_phone_secondary/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/partner_phone_secondary/__manifest__.py b/partner_phone_secondary/__manifest__.py new file mode 100644 index 000000000..0e34a0a6f --- /dev/null +++ b/partner_phone_secondary/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2020 - Iván Todorovich +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Secondary phone number on partners", + "summary": "Adds a secondary phone number on partners", + "license": "AGPL-3", + "version": "14.0.1.0.0", + "author": "Iván Todorovich, Odoo Community Association (OCA)", + "maintainers": ["ivantodorovich"], + "category": "Customer Relationship Management", + "depends": ["base"], + "website": "https://github.com/OCA/partner-contact", + "data": ["views/res_partner.xml"], +} diff --git a/partner_phone_secondary/models/__init__.py b/partner_phone_secondary/models/__init__.py new file mode 100644 index 000000000..91fed54d4 --- /dev/null +++ b/partner_phone_secondary/models/__init__.py @@ -0,0 +1 @@ +from . import res_partner diff --git a/partner_phone_secondary/models/res_partner.py b/partner_phone_secondary/models/res_partner.py new file mode 100644 index 000000000..03c71ad40 --- /dev/null +++ b/partner_phone_secondary/models/res_partner.py @@ -0,0 +1,17 @@ +# Copyright 2020 - Iván Todorovich +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + phone2 = fields.Char("Phone (Secondary)") + + @api.onchange("phone2", "country_id", "company_id") + def _onchange_phone2_validation(self): + # Compatibility with phone_validation + if hasattr(self, "phone_format"): + if self.phone2: + self.phone2 = self.phone_format(self.phone2) diff --git a/partner_phone_secondary/readme/CONTRIBUTORS.rst b/partner_phone_secondary/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..25a7ad47e --- /dev/null +++ b/partner_phone_secondary/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Iván Todorovich diff --git a/partner_phone_secondary/readme/DESCRIPTION.rst b/partner_phone_secondary/readme/DESCRIPTION.rst new file mode 100644 index 000000000..a264b3b75 --- /dev/null +++ b/partner_phone_secondary/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Adds a secondary phone number on partners diff --git a/partner_phone_secondary/tests/__init__.py b/partner_phone_secondary/tests/__init__.py new file mode 100644 index 000000000..6a02ed679 --- /dev/null +++ b/partner_phone_secondary/tests/__init__.py @@ -0,0 +1 @@ +from . import test_partner_phone_secondary diff --git a/partner_phone_secondary/tests/test_partner_phone_secondary.py b/partner_phone_secondary/tests/test_partner_phone_secondary.py new file mode 100644 index 000000000..f78aa2c62 --- /dev/null +++ b/partner_phone_secondary/tests/test_partner_phone_secondary.py @@ -0,0 +1,19 @@ +# Copyright 2020 - Iván Todorovich +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import Form, TransactionCase + + +class TestPartnerPhoneSecondary(TransactionCase): + def test_01_phone_validation_compatibility(self): + # This is here only to get code coverage. + with Form(self.env["res.partner"]) as form: + form.name = "French Partner" + form.country_id = self.env.ref("base.fr") + form.phone = "766666666" + form.phone2 = "766666666" + # It's not the purpose of this module to test phone_validation, + # nor how it formats phone numbers. Also it's not directly depended + # by this module. We do know for sure, though, that the same number + # is going to be formatted in the exact same way. + self.assertEqual(form.phone, form.phone2) diff --git a/partner_phone_secondary/views/res_partner.xml b/partner_phone_secondary/views/res_partner.xml new file mode 100644 index 000000000..bee7ff8aa --- /dev/null +++ b/partner_phone_secondary/views/res_partner.xml @@ -0,0 +1,19 @@ + + + + + + res.partner + + + + + + + + + + diff --git a/setup/partner_phone_secondary/odoo/addons/partner_phone_secondary b/setup/partner_phone_secondary/odoo/addons/partner_phone_secondary new file mode 120000 index 000000000..46b4a4fbb --- /dev/null +++ b/setup/partner_phone_secondary/odoo/addons/partner_phone_secondary @@ -0,0 +1 @@ +../../../../partner_phone_secondary \ No newline at end of file diff --git a/setup/partner_phone_secondary/setup.py b/setup/partner_phone_secondary/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/partner_phone_secondary/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)