Skip to Content
Menú
This question has been flagged
1 Respondre
5543 Vistes

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']), ]

Avatar
Descartar
Best Answer

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

Avatar
Descartar
Autor

Thanx....now it works

Related Posts Respostes Vistes Activitat
2
de set. 18
7074
9
de març 16
60939
1
de març 15
4799
2
de març 15
4571
0
de nov. 24
7