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

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

By
Drees Far
on 12/4/15, 5:07 AM 322 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
else:
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.

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)

Stats

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