Need constraints for Customer name field doesn't allow "spaces"?. is there any sql constraints?
Please give me suggestion.
Thanks and regards!
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)
and add _constraint as:
_constraints = [(_check_name, 'YOUR_MESSAGE', ['name'])]
Hop it will help!
Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!
About This Community
|Asked: 10/14/15, 5:21 AM|
|Seen: 875 times|
|Last updated: 11/3/15, 11:59 PM|