Odoo Help


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.


how to disable constraints based on checkbox in odoo ????

Deepak Krishna
on 11/23/15, 4:39 AM 404 views

Eg: having two fields 'age' a char field and 'enter_age' a check box.when ever i checked the check box then nly i can to enter the age.If entering the age then it will check for age>18 , otherwise it willnot check..Have written validation code for 'age'(age>18) and given the constraints too.

.Now my problem is whenever i chekked 'enter_age' then it will check for the constarints and gives a positive result...But whenever i didnt check the 'enter_age' then also they are checking for the constraints.....But i dont want to happen this..

how to disable the contraints for the second condition only???

plz give some answers..


Serpent Consulting Services Pvt. Ltd.

--Serpent Consulting Services Pvt. Ltd.--
| 6 6 8
Gandhinagar, India
--Serpent Consulting Services Pvt. Ltd.--

Serpent Consulting Services Pvt. Ltd. Your Odoo/OpenERP Solution, just an email away!

Serpent Consulting Services Pvt. Ltd.
On 11/23/15, 6:48 AM

Hello Deepak,

In your constraints, you should check age range only if your boolean field (checkbox) is true (checked).


#constraint method
def check_age(cr, uid, ids, context=None):
for rec in self.browse(cr, uid, ids, context=context):
if rec.check_age: #your checkbox. Check age only if checkbox is checked
if rec.age < 18: #raise constraint if age is less than 18
return False
return True

Hope this will help you.

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)


Asked: 11/23/15, 4:39 AM
Seen: 404 times
Last updated: 11/24/15, 12:30 AM