Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

Smart search of phone numbers.

Subscribe

Get notified when there's activity on this post

This question has been flagged
search12.0
2 Replies
5678 Views
Avatar
Lucas John

Hello everyone!

I have phone numbers in contacts written in different forms, with whitespaces, without, in group of 2 - 3 digits.

How to search in those all forms entering number in search form as one continous string of digits?

Let's say writing in search form - 123456789 i want to get results with phone numbers:

123456789

123 456 789

12 34 56 789

+33 12 34 56 789

etc.

The solution (stupid?) is to add wildcard "%" between each letter in search form - %1%2%3%4%5%6%7%8%9%

But maybe there is another - better solution? :)


0
Avatar
Discard
Jack Dane

Hello Lucas,

Would you prefer to keep the spaces in the numbers? As I have a solution which will remove all spaces, meaning that you wouldn't need the wildcard.

Thanks,

Avatar
Jack Dane
Best Answer

Yes "stupid proof" is what I specialise in! 

The best way would be to create either an automated action or a onchange event depending on your knowledge of creating Odoo apps you can do an onchange event which will remove all spaces from numbers as soon as they click off the field eg:

(requires creating an external app)

    @api.onchange("phone")
    def remove_spaces_from_phone_number(self):
        for record in self:
            if record.phone:
                record.phone = record.phone.replace(" ", "")

(do the same for mobile)

Or create an automated action in Settings->Tehnical->Automated Action. You would set the fields as Model->Contact, Action To Do->Execute Python Code and put "phone, mobile" in the On Change Fields Trigger. (Also make sure the module "base_automation" is installed. 

(can all be done within Odoo GUI)

The Python code would be: 

if record.phone:
  record["phone"] = record.phone.replace(" ", "")
if record.mobile:
  record["mobile"] = record.mobile.replace(" ", "")

For already existing phone numbers you can then write a scheduled action which would be:

all_contacts = env["res.partner"].search(["|", ("phone", "!=", False), ("mobile", "!=", False)])
for contact in all_contacts:
  if contact.phone:
    contact["phone"] = contact.phone.replace(" ", "")
  if contact.mobile:
    contact["mobile"] = contact.mobile.replace(" ", "")

You can run this once and it should be ok as users can no longer add spaces to numbers, or have this running once a day just incase.

I hope this helps!

1
Avatar
Discard
Lucas John
Author

Jack, I chose the solution from the GUI.

I installed base_automation, but I cannot see plase to put triggers - phone, mobile. Where it should be?

Maybe it's needed to somehow restart engine after installing base_automation?

Lucas John
Author

UPDATE. I somehow open "Planned Actions" instead of "Automated Action". It looks, that i have no more spaces in phone numbers so... IT WORKS!

Please PM me you address I will send you big beer :)

Jack Dane

Hello Lucas,

When you select Action To Do->Execute Python Code it should be below the field "Apply On".

Thanks,

Avatar
Lucas John
Author Best Answer

Hello Jack,

it depends, i cannot assume that all ODOO users will hold on new rule with entering phone number, does your solution will replace all existing numbers with space-less ones, and eventually remove spaces in number entered in future? In short, is it "stupid proof"? :)

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
How do I filter a spreadsheet pivot to the current/previous month
search
Avatar
Avatar
1
Jul 25
1438
Search a message Solved
search
Avatar
Avatar
1
Feb 25
1811
How To Set Char Type Field Only Have Number Input ODOO 12 ?
12.0
Avatar
2
Jan 25
7565
computed fields Solved
12.0
Avatar
Avatar
1
Apr 24
3559
running odoo 12 on ubuntu 22.04 OS, python 3.7, postgresql 15.0
12.0
Avatar
Avatar
1
Dec 23
6319
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now