This question has been flagged

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,

Avatar
Discard