Skip to Content
Menu
This question has been flagged
1 Reply
6196 Views

My onchange method works before writing some data in Mobile field.How can I fix this?Thank You.

class similar_contact(models.Model):

_inherit= 'res.partner'

@api.multi

@api.onchange("mobile")

def onchange_mobile(self):

mobile_id=self.search([('mobile','=',self.mobile)])

if mobile_id:

raise ValidationError(_('Similar Mobile Number exist'))

else:

raise ValidationError(_('No Similar Mobile'))

Avatar
Discard
Best Answer

Hello SuDarLy,

Put if condition before search any records because when form is load, onchange method is automatically called. Try below code.


class similar_contact(models.Model):

    _inherit= 'res.partner'

 

    @api.onchange("mobile")

    def onchange_mobile(self):

    if self.mobile:

        mobile_id=self.search([('mobile','=',self.mobile)])

        if mobile_id:

            raise ValidationError(_('Similar Mobile Number exist'))

        else:

            raise ValidationError(_('No Similar Mobile'))


Hope it will helps you.

Thanks,

Avatar
Discard
Author

Thank you so much Jignesh Mehta.

Related Posts Replies Views Activity
2
Jul 24
940
1
Jun 24
3562
1
Oct 23
8589
1
Oct 23
97
1
Aug 23
2192