Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
6775 มุมมอง

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.

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 24
2624
1
มิ.ย. 24
5097
1
ต.ค. 23
10785
1
ต.ค. 23
98
413 Request Entity Too Large แก้ไขแล้ว
1
ส.ค. 23
2193