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

Hi all,

I need to validate mobile field in res.partner object.

1.If i have not enter any value in mobile field, it should allow to save the record.

2.If i enter more than 10 digits or less than 10 digits means, it should show Warning while saving.

3.If i enter characters, it should show warning that cannot enter numerics.

Please share code if anyone done this code before and which way we can implement this requirement.

Thanks in advance.

아바타
취소

Validation 3:

Add this line too in to the above answer;

>>> if rec.phone_number and not str(rec.phone_number).isdigit():

            raise ValidationError(_("Cannot enter numerics"))

베스트 답변

Hi,

You can put your check within @api.constrains method, then you can do your python check if you want to use a 're' or use your own validations,

e.g:

@api.multi

@api.constrains('phone_number')

def _check_phone_number(self):

    for rec in self:

         if rec.phone_number and len(rec.phone_number) != 10"

             raise ValidationError(_("laplap..."))

     return True


Hope it will help

아바타
취소
베스트 답변

Hi,

Please check this link, Make the field as required for not allowing to save without entering the mobile number.https://stackoverflow.com/questions/16135069/python-validation-mobile-number

아바타
취소
작성자

Hello i want to make mobile no as mandatory

작성자

I dont want mobile as mandatory

베스트 답변

You can use https://github.com/daviddrysdale/python-phonenumbers to manage phone numbers on Odoo.

아바타
취소
베스트 답변

You might have a look at this true little gem: https://apps.odoo.com/apps/modules/10.0/inputmask_widget/

아바타
취소
관련 게시물 답글 화면 활동
4
12월 15
4720
1
12월 23
9246
1
6월 25
2138
2
10월 23
5815
1
9월 23
2212