تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
6846 أدوات العرض

Hi all,

Need constraints for Customer name field doesn't allow "spaces"?. is there any sql constraints?

Please give me suggestion.


Thanks and regards!

الصورة الرمزية
إهمال
أفضل إجابة

Jyothimani,

I think you need a constraint to check "name should not have space".

If it's so, you can create an odoo constraint and use regular expression to check for space in name, like

first add import re(to import regular expression class) then,

def _check_name(self, cr, uid, ids, context=None): 

    for record in self.browse(cr, uid, ids, context=context): 

# checking if regular expression find any ' '(space) in name string then it will return False

        has_space = re.compile(' ').search(record.name)

        if has_space:

            return False

    return True

 and add _constraint as:

_constraints = [(_check_name, 'YOUR_MESSAGE', ['name'])]

Hop it will help!    

الصورة الرمزية
إهمال
الكاتب

Thanks!!!!

Thank you!!!!

أفضل إجابة

You can try this

def _check_string(self, cr, uid, ids, context=None):

    for data in self.browse(cr, uid, ids, context=context)

          if data.isspace() == True:

                 return False

return True

_constraints = [

(_check_string, 'Space is not allow', ['field name'])

]

الصورة الرمزية
إهمال
الكاتب

Very thanks Solanki Shamji!!!!!. Its working.....

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
مارس 15
10678
3
نوفمبر 22
5863
0
أغسطس 20
4444
1
يونيو 17
1282
2
سبتمبر 21
3734