Odoo Help

0

Field limitation/filtering in model

By
Yury
on 9/14/13, 4:52 AM 845 views

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!

1
Sudhir Arya (SA)
On 9/14/13, 5:55 PM

There are lots of ways you can go for.

  1. 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.
  2. Best way is to define a custom constraint on that field.

For ex:

def _check_age(self,  cr,  uid, ids, context=None):
    obj = self.browse(cr, uid, ids[0], 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.

Thanks! Now I understend better how openerp works!

Yury
on 9/14/13, 8:11 PM

About This Community

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

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 9/14/13, 4:52 AM
Seen: 845 times
Last updated: 3/16/15, 8:10 AM