콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
1 회신
6763 화면

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
7월 24
2598
1
6월 24
5061
1
10월 23
10738
1
10월 23
98
1
8월 23
2193