Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

Need constraints for Customer name field doesn't allow "spaces"?

By
Jo
on 10/14/15, 5:21 AM 875 views

Hi all,

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

Please give me suggestion.


Thanks and regards!

1

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 10/14/15, 6:23 AM

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!!!!

Jo
on 10/14/15, 8:12 AM
1

Solanki Shamji

--Solanki Shamji--
1293
| 5 2 6
Baroda, India
--Solanki Shamji--

Hello!

Solanki Shamji
On 10/14/15, 6:25 AM

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.....

Jo
on 10/14/15, 8:12 AM

Your Answer

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

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/14/15, 5:21 AM
Seen: 875 times
Last updated: 11/3/15, 11:59 PM