Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
2907 Lượt xem

Hi!!

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

Pleas, how can i do it help

Ảnh đại diện
Huỷ bỏ

Elaborate your purpose little bit please !

Tác giả

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.

Câu trả lời hay nhất

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()
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất


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)

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 3 25
1387
0
thg 1 25
3470
1
thg 8 23
14810
change password Đã xử lý
1
thg 8 23
13471
1
thg 7 23
10433