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

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/

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
4
ธ.ค. 15
4652
1
ธ.ค. 23
9109
No mobile phone in V18.2 ?? แก้ไขแล้ว
1
มิ.ย. 25
1958
2
ต.ค. 23
5675
1
ก.ย. 23
2147