From 16334e190b3c7a147ff3eb55278a076dc3ff6334 Mon Sep 17 00:00:00 2001 From: ArnauCForgeFlow Date: Fri, 22 Dec 2023 10:56:47 +0100 Subject: [PATCH] [MIG] hr_phone: Migration to 16.0 --- hr_phone/README.rst | 12 ++++----- hr_phone/__manifest__.py | 2 +- hr_phone/models/hr_employee.py | 37 +++++++++++++++++++++++--- hr_phone/static/description/index.html | 8 +++--- hr_phone/tests/test_phone.py | 4 +-- test-requirements.txt | 1 + 6 files changed, 48 insertions(+), 16 deletions(-) create mode 100644 test-requirements.txt diff --git a/hr_phone/README.rst b/hr_phone/README.rst index 1e7c2ab3c..aecc0949b 100644 --- a/hr_phone/README.rst +++ b/hr_phone/README.rst @@ -7,7 +7,7 @@ HR Phone !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:567f6f2f6342635a3be6c6ca511d3c2f032533faf09049d59ea905a300a13bab + !! source digest: sha256:b0f180243908899cb6be2a3bcd701ddb262d7030d54ba011e400a50b7868eaa2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -17,13 +17,13 @@ HR Phone :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fconnector--telephony-lightgray.png?logo=github - :target: https://github.com/OCA/connector-telephony/tree/14.0/hr_phone + :target: https://github.com/OCA/connector-telephony/tree/16.0/hr_phone :alt: OCA/connector-telephony .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/connector-telephony-14-0/connector-telephony-14-0-hr_phone + :target: https://translation.odoo-community.org/projects/connector-telephony-16-0/connector-telephony-16-0-hr_phone :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png - :target: https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&target_branch=14.0 + :target: https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&target_branch=16.0 :alt: Try me on Runboat |badge1| |badge2| |badge3| |badge4| |badge5| @@ -42,7 +42,7 @@ 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 to smash it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -80,6 +80,6 @@ Current `maintainer `__: |maintainer-alexis-via| -This module is part of the `OCA/connector-telephony `_ project on GitHub. +This module is part of the `OCA/connector-telephony `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/hr_phone/__manifest__.py b/hr_phone/__manifest__.py index d3f3e5763..1c0f0dec5 100644 --- a/hr_phone/__manifest__.py +++ b/hr_phone/__manifest__.py @@ -4,7 +4,7 @@ { "name": "HR Phone", - "version": "14.0.1.0.0", + "version": "16.0.1.0.0", "category": "Phone", "license": "AGPL-3", "summary": "Validate phone numbers in HR", diff --git a/hr_phone/models/hr_employee.py b/hr_phone/models/hr_employee.py index 7f694351c..906660da0 100644 --- a/hr_phone/models/hr_employee.py +++ b/hr_phone/models/hr_employee.py @@ -4,22 +4,53 @@ from odoo import api, models +# phone_validation is not officially in the depends of hr, but we would like +# to have the formatting available in hr, not in event_sms -> do a conditional +# import just to be sure +try: + from odoo.addons.phone_validation.tools.phone_validation import phone_format +except ImportError: + + def phone_format( + number, + country_code, + country_phone_code, + force_format="INTERNATIONAL", + raise_exception=True, + ): + return number + class HrEmployeePrivate(models.Model): _name = "hr.employee" - _inherit = ["hr.employee", "phone.validation.mixin"] + _inherit = ["hr.employee"] _phone_name_sequence = 30 _phone_name_fields = ["mobile_phone"] # work_phone is now a computed field that take the value address_id.phone # Don't put emergency_phone in _phone_name_fields because it is not a phone # number of the employee + def _phone_format(self, number, country=None): + """Call phone_validation formatting tool function. Returns original + number in case formatting cannot be done (no country, wrong info, ...)""" + if not number or not country: + return number + new_number = phone_format( + number, + country.code, + country.phone_code, + force_format="E164", + raise_exception=False, + ) + return new_number if new_number else number + @api.onchange("mobile_phone") def mobile_phone_change(self): if self.mobile_phone: - self.mobile_phone = self.phone_format(self.mobile_phone) + country = self.env.company.country_id + self.mobile_phone = self._phone_format(self.mobile_phone, country) @api.onchange("emergency_phone") def emergency_phone_change(self): if self.emergency_phone: - self.emergency_phone = self.phone_format(self.emergency_phone) + self.emergency_phone = self._phone_format(self.emergency_phone) diff --git a/hr_phone/static/description/index.html b/hr_phone/static/description/index.html index 68d392db5..b67f71a66 100644 --- a/hr_phone/static/description/index.html +++ b/hr_phone/static/description/index.html @@ -367,9 +367,9 @@

HR Phone

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:567f6f2f6342635a3be6c6ca511d3c2f032533faf09049d59ea905a300a13bab +!! source digest: sha256:b0f180243908899cb6be2a3bcd701ddb262d7030d54ba011e400a50b7868eaa2 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

Beta License: AGPL-3 OCA/connector-telephony Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/connector-telephony Translate me on Weblate Try me on Runboat

This module validates phone numbers in the Employee form, just like the phone_validation module valide phone numbers in the Partner form. It also adds phone number lookup on employees on incoming calls.

Table of contents

@@ -389,7 +389,7 @@

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 to smash it by providing a detailed and welcomed -feedback.

+feedback.

Do not contact contributors directly about support or help with technical issues.

@@ -415,7 +415,7 @@

Maintainers

promote its widespread use.

Current maintainer:

alexis-via

-

This module is part of the OCA/connector-telephony project on GitHub.

+

This module is part of the OCA/connector-telephony project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

diff --git a/hr_phone/tests/test_phone.py b/hr_phone/tests/test_phone.py index f0fb44d03..306ae294b 100644 --- a/hr_phone/tests/test_phone.py +++ b/hr_phone/tests/test_phone.py @@ -18,8 +18,8 @@ def setUp(self): def test_lookup(self): res = self.phco.get_record_from_phone_number("0678727272") self.assertIsInstance(res, tuple) - self.assertEqual(res[0], "hr.employee") - self.assertEqual(res[1], self.test_record.id) + self.assertEqual(res[0], "res.partner") + self.assertEqual(res[1], self.test_record.work_contact_id.id) self.assertEqual( res[2], self.test_record.with_context(callerid=True).name_get()[0][1] ) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 000000000..87ca42edb --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-base_phone@git+https://github.com/OCA/connector-telephony.git@refs/pull/300/head#subdirectory=setup/base_phone