Odoo Help


How to block duplicating RECORDS (with the same employee_id)?

Vale Trood
on 12/4/15, 5:07 AM 716 views

Hello everybody!!!!

Please, i have a class that contains an employee_id field.

So for the different records of my class, i want to block those with the same employee_id.

I have tried to work with sql_constraint but it doesnt work well.

Here is my code.

('uniq_name', 'unique(employee_id)', "A stuff already exists with this name . Stuff's name must be unique!"),


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

obj = self.pool.get('solde.compte')
obj_ids = obj.search(cr, uid, [('employee_id', '=',employee_id)])
vals = obj.read(cr,uid,obj_ids,['id','employee_id'],context=context)
if vals == []:
res = {'value':{'remaining_leave': self.get_inputs(cr, uid, ids, employee_id, context=context),
return res
My_error_Msg = 'Attention!! Vous avez deja rempli un SOLDE DE TOUT COMPTE de cet employe'
raise osv.except_osv(_("Error!"), _(My_error_Msg))
return False

Thanks a lot in advance.

Best Regards.

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

1 follower(s)


Asked: 12/4/15, 5:07 AM
Seen: 716 times
Last updated: 12/4/15, 5:45 AM