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

How to normalize the zip code of a new created account on the website?

Subscribe

Get notified when there's activity on this post

This question has been flagged
codecapitallowercasezipnormalize
10 Replies
7671 Views
Avatar
Pascal Tremblay

Hello all,

When a new user create an account on our site, what is the easier way to be sure that the zip code is alway entered like :

G8E 5M7 (with capitals letters an a space)

and not like :

g8e5m7

g8e 5m7

G8e 5M7

etc.

Do you have an idea of an easy method to manage it? Or should i dive in python once again?

0
Avatar
Discard
Dr Obx

In my case (custom module) I did it that way:

	post = record.buyer_postcode.strip(' ')
	code = "%s %s" %(post[:-3].strip(), post[-3:])
	postcode = code.upper()
	record.write({'buyer_postcode': postcode.upper()})
So if you want you can modify py, add action "Validate" or something ....
Dr Obx

But in your case it will be better use jQuery as Axel suggested.

Pascal Tremblay
Author

Thanks a lot!

Dr Obx
post = record.buyer_postcode.strip(' ')# striping postcode to get only string of characters and digits
	code = "%s %s" %(post[:-3].strip(), post[-3:])#joining it back with one space between
	postcode = code.upper()# changing to uppercase
	record.write({'buyer_postcode': postcode.upper()})# writing new value into the field or database
Avatar
Axel Mendoza
Best Answer

You could do it using a mask on the input field and normally in combination with a regular expression to validate the format in js and in python to avoid mistakes, you will be ok

See examples here:

https://igorescobar.github.io/jQuery-Mask-Plugin/

1
Avatar
Discard
Pascal Tremblay
Author

Thanks Axel. Would you know in which file I should work in odoo 8 to put this code?

Pascal Tremblay
Author

I would say that I have to install myself the jQuery Mask Plugin. Is it the case?

Dr Obx

I would try in base/static/src/js/apps.js because in base/res is res_partner so this is the best place to start or as separate module .... but i'm not an expert :) (i'm a total amateur)

Pascal Tremblay
Author

thanks again. I'll see all of this.

Avatar
Pascal Tremblay
Author Best Answer

Here is our complete solution. Thanks to Dr Obx and Axel.

1) Download jquery mask plugin

2) Install it in ourmodule/static/src/js

3) Load the script

        <template id="ourmodule.assets_frontend" inherit_id="website.assets_frontend" name="Shop">
            <xpath expr="." position="inside">
                <script type="text/javascript" src="/website_lapagept/static/src/js/website_sale_clear_cart.js"></script>
                <script type="text/javascript" src="/website_lapagept/static/src/js/jquery-mask-plugin-master/src/jquery.mask.js"></script>
            </xpath>
        </template>


4) Add this in the file ourmodule/static/src/js/jquery-mask-plugin-master/src/jquery.mask.js

$(document).ready(function(){
//  $('.zipcode').mask('A0A 0A0');
        $('.zipcode').mask('Y9Y 9Y9',
                           {'translation': {
                                        9: {pattern: /[0-9]/},  
                                        Y: {pattern: /[A-Z]/}
                                      }
                                });
});


5) Add the correct .zipcode class to the field that should have the mask

                  <div t-attf-class="form-group #{error.get('zip') and 'has-error' or ''} col-lg-6">
                      <label class="control-label" for="zip">Code postal</label>
                      <input type="text" name="zip" class="form-control zipcode" t-att-value="checkout.get('zip')"/>
                  </div>


AND ALSO

                  <div t-attf-class="form-group #{error.get('shipping_zip') and 'has-error' or ''} col-lg-6">
                      <label class="control-label" for="shipping_zip" style="font-weight: normal">Zip / Postal Code</label>
                      <input type="text" name="shipping_zip" class="form-control zipcode" t-att-value="checkout.get('shipping_zip', '')" t-att-readonly=" 'readonly' if shipping_id &gt;= 0 else ''"/>
                  </div>



And it works fine!

1
Avatar
Discard
Axel Mendoza

Exactly as you do it

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
Extracting company's information
code company zip information
Avatar
Avatar
1
Mar 15
5061
.update() method not updating values
code
Avatar
0
Sep 23
2701
Why is the hr.attendance date column called "name"?
code
Avatar
0
Aug 16
5060
How to refresh the form view in coding in openerp 7?
code
Avatar
0
Mar 15
5536
line code.
code
Avatar
0
Jul 24
3437
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