Odoo Help


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

Pascal Tremblay
on 3/8/16, 10:10 PM 1,396 views

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 :


g8e 5m7

G8e 5M7


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

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
on 3/9/16, 4:32 AM

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

Dr Obx
on 3/9/16, 4:33 AM

Thanks a lot!

Pascal Tremblay
on 3/9/16, 9:48 AM
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
Dr Obx
on 3/9/16, 12:05 PM

Axel Mendoza

--Axel Mendoza--
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 3/9/16, 2:37 AM

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:


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

Pascal Tremblay
on 3/9/16, 9:48 AM

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

Pascal Tremblay
on 3/9/16, 10:21 AM

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)

Dr Obx
on 3/9/16, 12:02 PM

thanks again. I'll see all of this.

Pascal Tremblay
on 3/9/16, 12:35 PM

Pascal Tremblay

--Pascal Tremblay--
| 5 3 7
Alma, Canada
--Pascal Tremblay--

Pascal Tremblay
On 3/9/16, 4:20 PM

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>

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

//  $('.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 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 ''"/>

And it works fine!

Exactly as you do it

Axel Mendoza
on 3/9/16, 6:07 PM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/8/16, 10:10 PM
Seen: 1396 times
Last updated: 3/9/16, 4:20 PM