Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] phone_validation: brazilian phone numbers #153282

Conversation

ande-odoo
Copy link
Contributor

Current behavior:

Brazilian phone numbers are not managed correctly
following the 2016 changes in Brazil.
(Adding a 9 to mobile phone numbers)

Fix:

Patched the phonenumbers library, adding a 9
at the right place for mobile phone numbers.

opw-3694150


I confirm I have signed the CLA and read the PR guidelines at www.odoo.com/submit-pr

@robodoo
Copy link
Contributor

robodoo commented Feb 8, 2024

@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Feb 8, 2024
Copy link
Contributor

@nle-odoo nle-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me if the number whatsapp send us is lke +55 11 6123-4567 👍

intl_number_format exists in the region_BR.py file of phonenumbers since june 2015 (from this commit) which corresponds to version 7.0.6 and ubuntu of 2016 or end of 2015, so this seems safe.

I tried installing 7.0.5 to test what error we would get if we had an old version, but with python 3.6 and 3.11 I can't install it because of an issue in a regex:

        File "/tmp/pip-install-bwcr44br/phonenumbers_2576ab7f89c349cd98849c55abbcc91a/phonenumbers/phonenumbermatcher.py", line 120, in <module>
          _PATTERN = re.compile(u("(?:") + _LEAD_CLASS + _PUNCTUATION + u(")") + _LEAD_LIMIT +
        ...
        File "/usr/lib/python3.11/re/_parser.py", line 843, in _parse
          raise source.error('global flags not at the start '
      re.error: global flags not at the start of the expression at position 57

So this seems safe like this and good to keep like thi (if the version with the problem is not possible to install), but otherwise we could check the version or have a try:; except AttributeError: pass

@ande-odoo ande-odoo marked this pull request as ready for review February 9, 2024 16:41
@C3POdoo C3POdoo requested a review from a team February 9, 2024 16:43
@tde-banana-odoo
Copy link
Contributor

As we merged whatsapp in 16.3, shouldn't we fix in 16.3 ? It is a request coming from whatsapp users mainly.

@ande-odoo ande-odoo marked this pull request as draft February 15, 2024 10:13
@ande-odoo ande-odoo force-pushed the 17.0-OPW_3694150-phone_validation-brazil_phone_numbers-ande branch from d8db73e to 91ef058 Compare February 15, 2024 10:18
@ande-odoo ande-odoo changed the base branch from 17.0 to saas-16.3 February 15, 2024 10:19
@ande-odoo ande-odoo changed the base branch from saas-16.3 to tmp.saas-16.3 February 15, 2024 10:22
@ande-odoo ande-odoo changed the base branch from tmp.saas-16.3 to saas-16.3 February 15, 2024 10:23
@robodoo
Copy link
Contributor

robodoo commented Feb 15, 2024

@ande-odoo ande-odoo marked this pull request as ready for review February 15, 2024 10:28
@C3POdoo C3POdoo requested a review from a team February 15, 2024 10:37
Copy link
Contributor

@reth-odoo reth-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment + I wonder if we really need to patch the whole library for that.

If it's super safe and we're confident in this then good, but otherwise it might be worth considering solving this on the side of whatsapp where the format is guaranteed and we don't need to play with regex. As this format is not valid today anyway, and the reason we're getting it is because whatsapp is stupid and gives us the "number id" where we have to infer the real number.

That regex is a bit scary is all ^^

addons/phone_validation/lib/phonenumbers_patch/__init__.py Outdated Show resolved Hide resolved
@ande-odoo
Copy link
Contributor Author

Hi @odoo/rd-sm-phishing Could I get a review ? Thanks !

Copy link
Contributor

@reth-odoo reth-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As patterns are matched in order of the array anyway it should be fairly safe so seems ok to go with this indeed.

I think it could be good for the commit message to link towards the file of the lib and wikipedia article. And specify that the pattern will only apply if none of the other formats in the lib match, which was a point of confusion for me.

ok for me code-wise, adding [6-9] or [68] could be good for accuracy/clarity

Thanks for the thorough explanation :)

addons/phone_validation/lib/phonenumbers_patch/__init__.py Outdated Show resolved Hide resolved
@ande-odoo ande-odoo force-pushed the 17.0-OPW_3694150-phone_validation-brazil_phone_numbers-ande branch from 91ef058 to 22c30b4 Compare March 26, 2024 09:39
@ande-odoo
Copy link
Contributor Author

Hi @reth-odoo I have added the 6 8 9 filter for mobile numbers (7 is already filtered in the previous regex)

Copy link
Contributor

@reth-odoo reth-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems legit to force fix invalid numbers then 👌
(pinging @tde-banana-odoo again as he started the review + is much better versed in phone stuff)

addons/phone_validation/tests/test_phonenumbers_patch.py Outdated Show resolved Hide resolved
@tde-banana-odoo
Copy link
Contributor

@reth-odoo But I hate regexes.

Current behavior:
Brazilian phone numbers are not managed correctly
following the 2016 changes in Brazil.
(Adding a 9 to mobile phone numbers)

Fix:
Patched the phonenumbers library, adding a 9
at the right place for mobile phone numbers.

opw-3694150
@ande-odoo ande-odoo force-pushed the 17.0-OPW_3694150-phone_validation-brazil_phone_numbers-ande branch from 22c30b4 to dce570f Compare March 27, 2024 16:15
Copy link
Contributor

@reth-odoo reth-odoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it, it's just a difficult-to-read limited language that has inconsistent syntax and semantics across implementations. What's there to dislike?

That aside.. I'll take the fall. lgtm thanks for the changes

@tde-banana-odoo
Copy link
Contributor

@robodoo r+

robodoo pushed a commit that referenced this pull request Mar 28, 2024
Current behavior:
Brazilian phone numbers are not managed correctly
following the 2016 changes in Brazil.
(Adding a 9 to mobile phone numbers)

Fix:
Patched the phonenumbers library, adding a 9
at the right place for mobile phone numbers.

opw-3694150

closes #153282

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
@robodoo robodoo closed this Mar 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants