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

Field limitation/filtering in model

By
Yury
on 9/14/13, 4:52 AM 588 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)

--Sudhir Arya (SA)--
10150
| 6 8 8
Ahmedabad, India
--Sudhir Arya (SA)--

Working as an OpenERP/Odoo developer and a Team Leader 

Top 5 Odoo contributor On Stackoverflow

LinkedIn

Blog

Stackoverflow

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

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

0 follower(s)

Stats

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