Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
6849 Näkymät

Hi all,

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

Please give me suggestion.


Thanks and regards!

Avatar
Hylkää
Paras vastaus

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!    

Avatar
Hylkää
Tekijä

Thanks!!!!

Thank you!!!!

Paras vastaus

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'])

]

Avatar
Hylkää
Tekijä

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

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
2
maalisk. 15
10680
3
marrask. 22
5866
0
elok. 20
4445
1
kesäk. 17
1282
2
syysk. 21
3740