[19.0] Proposal: phone_autoformat - automatically format phone numbers on save

Open
#3,839 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
12/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
backend

Research direction

This is a proposal for a new module, not a defined change, so there is no file to start from yet. Read the three open questions in the thread, since the maintainers' answers on repository placement, existing OCA coverage and the res.partner mixin approach decide whether any code is written. The issue names the phone_validation dependency and the phonenumbers library as the pieces to check. Done means a maintainer has agreed the design, and only then a PR on the 19.0 branch.

Written by the indexing model from the issue text.

Description

enhancement

Summary

I'd like to propose a new module, phone_autoformat, for this repository
(branch 19.0). It formats phone numbers automatically so every number in the
database follows the same format, without users having to retype them.

Problem

Odoo stores phone numbers exactly as typed, so a database ends up with
0300 1234567, +923001234567, 0092-300-1234567 and so on. This makes
searching, matching and dialing inconsistent. Odoo core has phone_validation
(with the formatting helpers), but it does not apply them automatically to
stored fields.

What the module does

  • Reformats phone fields when the user leaves the field, and again on
    create/write (so imports and API calls are covered too).
  • Handles every stored, editable text field whose name contains phone or
    mobile, including custom fields.
  • Configurable in Settings: International, E.164, National, RFC 3966, or
    disabled.
  • Optionally allows several numbers in one field (comma/semicolon separated);
    each one is formatted on its own.
  • Numbers that cannot be parsed are left exactly as typed.
  • Uses the contact's country, then the company's country, to parse numbers
    typed without a + prefix.

It depends only on base, phone_validation and the phonenumbers library
(already used by core). The module is on my fork and I have tested it on an
Odoo 19 instance. It includes tests and the standard readme/ fragments.

Questions

  1. Do you think this fits server-tools, or would another repository
    (for example connector-telephony or partner-contact) be a better home?
  2. Does an existing OCA module already cover this? I could not find one, but
    I may have missed it. If so, I'm happy to contribute there instead.
  3. Is applying the formatting through a mixin on res.partner acceptable, or
    would you prefer a different approach (for example a field widget only)?

If this is welcome, I will open a PR on the 19.0 branch and sign the CLA
through the bot as usual. Bridge modules for CRM leads and employees would
be separate, later PRs to the matching repositories.

Thanks for your time and for reviewing this!

Dominant language
Python
Stars
960
Forks
1.7k
Avg merge
5d 23h
Merged PRs (30d)
15

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from OCA/server-tools

All issues in OCA/server-tools

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.