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

Hi!!

I want to controle a field if it contains a space (\t) in odoo v8.

Pleas, how can i do it help

อวตาร
ละทิ้ง

Elaborate your purpose little bit please !

ผู้เขียน

I have a field called project in which i wouldnt have empty string so i put it required= True and now i want it to NOT COTAIN a space.

คำตอบที่ดีที่สุด

You should define a python constraint

_constraints = [(_function_name, warning_string, list_of_relevant_attributes)]
ex :

_constraints = [(_check_empty_string, 'The name cannot contains only spaces", ['name'])
def _check_empty_string(self, cr, uid, ids, context=None) : (old API way)
    project = self.browse(cr,uid, ids, context=context)
    return not project.name.isspace()
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด


for v8 you can write constraint like to validate the space,

	@api.constrains('name')
def check_name(self):
if self.name.isspace():
raise ValidationError("Name can not be Empty")

name = fields.Char('Name', required=True)

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มี.ค. 25
1420
0
ม.ค. 25
3502
1
ส.ค. 23
14869
change password แก้ไขแล้ว
1
ส.ค. 23
13517
1
ก.ค. 23
10498