Skip to content

Commit

Permalink
[MIG] hr_phone: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnauCForgeFlow committed Dec 22, 2023
1 parent 90908e3 commit 0fb127d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
12 changes: 6 additions & 6 deletions hr_phone/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand All @@ -42,7 +42,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/connector-telephony/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 <https://github.com/OCA/connector-telephony/issues/new?body=module:%20hr_phone%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/connector-telephony/issues/new?body=module:%20hr_phone%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Expand Down Expand Up @@ -80,6 +80,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-alexis-via|

This module is part of the `OCA/connector-telephony <https://github.com/OCA/connector-telephony/tree/14.0/hr_phone>`_ project on GitHub.
This module is part of the `OCA/connector-telephony <https://github.com/OCA/connector-telephony/tree/16.0/hr_phone>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion hr_phone/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
37 changes: 34 additions & 3 deletions hr_phone/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Check warning on line 12 in hr_phone/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_phone/models/hr_employee.py#L12

Added line #L12 was not covered by tests

def phone_format(

Check warning on line 14 in hr_phone/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_phone/models/hr_employee.py#L14

Added line #L14 was not covered by tests
number,
country_code,
country_phone_code,
force_format="INTERNATIONAL",
raise_exception=True,
):
return number

Check warning on line 21 in hr_phone/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_phone/models/hr_employee.py#L21

Added line #L21 was not covered by tests


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(

Check warning on line 38 in hr_phone/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_phone/models/hr_employee.py#L37-L38

Added lines #L37 - L38 were not covered by tests
number,
country.code,
country.phone_code,
force_format="E164",
raise_exception=False,
)
return new_number if new_number else number

Check warning on line 45 in hr_phone/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_phone/models/hr_employee.py#L45

Added line #L45 was not covered by tests

@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)

Check warning on line 51 in hr_phone/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_phone/models/hr_employee.py#L50-L51

Added lines #L50 - L51 were not covered by tests

@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)

Check warning on line 56 in hr_phone/models/hr_employee.py

View check run for this annotation

Codecov / codecov/patch

hr_phone/models/hr_employee.py#L56

Added line #L56 was not covered by tests
8 changes: 4 additions & 4 deletions hr_phone/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,9 +367,9 @@ <h1 class="title">HR Phone</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:567f6f2f6342635a3be6c6ca511d3c2f032533faf09049d59ea905a300a13bab
!! source digest: sha256:b0f180243908899cb6be2a3bcd701ddb262d7030d54ba011e400a50b7868eaa2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/connector-telephony/tree/14.0/hr_phone"><img alt="OCA/connector-telephony" src="https://img.shields.io/badge/github-OCA%2Fconnector--telephony-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/connector-telephony-14-0/connector-telephony-14-0-hr_phone"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/connector-telephony/tree/16.0/hr_phone"><img alt="OCA/connector-telephony" src="https://img.shields.io/badge/github-OCA%2Fconnector--telephony-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/connector-telephony-16-0/connector-telephony-16-0-hr_phone"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module validates phone numbers in the Employee form, just like the <em>phone_validation</em>
module valide phone numbers in the Partner form. It also adds phone number lookup on employees on incoming calls.</p>
<p><strong>Table of contents</strong></p>
Expand All @@ -389,7 +389,7 @@ <h1><a class="toc-backref" href="#toc-entry-1">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/connector-telephony/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/connector-telephony/issues/new?body=module:%20hr_phone%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/connector-telephony/issues/new?body=module:%20hr_phone%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -415,7 +415,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/alexis-via"><img alt="alexis-via" src="https://github.com/alexis-via.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/connector-telephony/tree/14.0/hr_phone">OCA/connector-telephony</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/connector-telephony/tree/16.0/hr_phone">OCA/connector-telephony</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions hr_phone/tests/test_phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
odoo-addon-base_phone@git+https://github.com/OCA/connector-telephony.git@refs/pull/300/head#subdirectory=setup/base_phone

0 comments on commit 0fb127d

Please sign in to comment.