تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
6756 أدوات العرض

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'))

الصورة الرمزية
إهمال
أفضل إجابة

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,

الصورة الرمزية
إهمال
الكاتب

Thank you so much Jignesh Mehta.

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
يوليو 24
2593
1
يونيو 24
5057
1
أكتوبر 23
10727
1
أكتوبر 23
98
1
أغسطس 23
2193