Odoo Help


constraint not working porperly

on 11/27/13, 6:57 AM 1,719 views

hie...I am new in openerp. Here is my code. When condition is met properly, it throws exception which is correct. But when condition is not met, it still throws exception. How??????

def _check_resign_date(self,cr,uid,ids,context=None):

    for rec in self.browse(cr,uid,ids):
        if rec.status == 'resign':
            if rec.resign_date > rec.separation_date:
                 raise osv.except_osv(('Alert!'),('Resignation date should not be greater than Separation Date.'))
        elif rec.status == 'transfer':
            if rec.transfer_date > rec.separation_date:
                 raise osv.except_osv(('Alert!'),('Transfer date should not be greater than Separation Date.'))
    return True

_constraints = [ (_check_resign_date,'a',['id']), ]


Anil R. Kesariya

--Anil R. Kesariya--
| 6 5 8
Rajkot, India
--Anil R. Kesariya--

Odoo Techno Functional Expert

* Engaged with odoo since May - 2012.

* Customise existing module or develop new module base on customer requirement.

* Played key developer role in many past and running projects.

* Expert in requirement gathering of business and transforming requirement into odoo platform.

* Major expertise in core modules, database, report development and theme development.

* Integration expert.

Linkedin  : https://in.linkedin.com/in/anil-kesariya-97b20a66

Anil R. Kesariya
On 11/27/13, 7:31 AM

Hello vikram,

Correct the argument list on your constraint set.

Brief description about arguments

_constraints = [(_check_resign_date,'YOur warning Message !!', ['field_name'])]

1) First argument is your method name 2) The second argument is warning message when your method return false. 3) It must be field name of your model when that field will change than this constraint will trigger. so make sure you are giving the exact field name.

No need to raise exception from there return true or false based on your warning message will trigger from constraint. I suggeest you need to pass both date on your constraint.

like :

_constraints = [(_check_resign_date,'YOur warning Message !!', ['status','resign_date','separation_date'])]

return true or false from your method message will trigger from constraint.

Hope this will help.

Regards, Anil

Thanx....now it works

on 11/27/13, 8:22 AM

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.


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)


Asked: 11/27/13, 6:57 AM
Seen: 1719 times
Last updated: 3/16/15, 8:10 AM