Odoo Help

Welcome!

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

1

Trying to apply onchange in res.partner zip field

By
DM
on 5/26/15, 4:48 AM 1,079 views

Hello odoo community,

I have a weird issue im trying to apply onchange function to res.partner zip field

Nothing happens when im trying to change zip  field , but if i choose some other field or apply the same function to a button, it would work ...

I dont understand what the issue is ...

New api code example:

@api.one

@api.onchange('zip')

def validate_uk_postcode(self):

for record in self:

if record.country_id.id==233:

zip=record.zip.upper()

zip_in_line=s = zip.replace(" ", "") 

self.env.cr.execute("select postcode from ct_uk_postcodes_ct_uk_postcodes where postcode='{0}'".format(zip_in_line))

res2 = self.env.cr.fetchone()

if res2==None:

raise ValidationError("Post Code is invalid, Please make sure that country and post code is correct!")

results:

Nothing happen

Also i tryed to use old api

Old api example:

def onchange_zipcode(self, cr, uid, ids, context=None):

for record in self.browse(cr,uid,ids):

if record.country_id.id==233: 

zip=record.zip.upper()

zip_in_line=s = zip.replace(" ", "")

cr.execute("select postcode from ct_uk_postcodes_ct_uk_postcodes where postcode='{0}'".format(zip_in_line))

res = cr.fetchone()

if res==None: 

raise ValidationError("Post Code is invalid, Please make sure that country and post code is correct!")

result:

Nothing Happens

Xml

<field name="zip" placeholder="ZIP" style="width: 20%%" attrs="{'readonly': [('use_parent_address','=',True)]}" on_change="onchange_zipcode()"/> 


Thank you,

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 5/26/15, 4:48 AM
Seen: 1079 times
Last updated: 10/23/15, 9:18 AM