Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
10 Odpowiedzi
6690 Widoki

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?

Awatar
Odrzuć

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 ....

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

Autor

Thanks a lot!

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
Najlepsza odpowiedź

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/

Awatar
Odrzuć
Autor

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

Autor

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

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)

Autor

thanks again. I'll see all of this.

Autor Najlepsza odpowiedź

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!

Awatar
Odrzuć

Exactly as you do it

Powiązane posty Odpowiedzi Widoki Czynność
1
mar 15
4142
0
wrz 23
1498
0
sie 16
3682
0
mar 15
4446
0
lip 24
3437