Hello everyone! I'm new in OpenERP (just a few days) and I would like to create a simple model with 2 fields: "name" (text) and "age"(integer)
- name - is required and can contain string not longer than 20 symbols - it's easy
- age - is required and should contain integer greater or equal than 20
My question is - how I can verify or check imput values for field "age"?
Thanks a lot!
There are lots of ways you can go for.
- You have to override create and write method and in that method you can check whether value of age is greater than or equal to 20. You may find many examples about how to override create and write methods.
- Best way is to define a custom constraint on that field.
def _check_age(self, cr, uid, ids, context=None): obj = self.browse(cr, uid, ids, context=context) if obj.your_age_field < 20: return False return True _constraints = [(_check_age, 'Age must be greater than or equal to 20.', ['your_age_field']),]
Hope this will help you.
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: 9/14/13, 4:52 AM|
|Seen: 563 times|
|Last updated: 3/16/15, 8:10 AM|