#custom unique name constraint with ignore case
def _check_unique_insesitive(self, cr, uid, ids, context=None):
list_ids = self.search(cr, uid , [], context=context)
lst = [list_id.name.lower() for list_id in self.browse(cr, uid, list_ids, context=context) if list_id.name and list_id.id not in ids]
for self_obj in self.browse(cr, uid, ids, context=context):
if self_obj.name and self_obj.name.lower() in lst:
return False
return True
Use as following in your class :
_constraints = [(_check_unique_insesitive, <error_message>, ['<field_name>'])]
e.g : _constraints = [(_check_unique_insesitive, 'Name already exists', ['name'])]
Thanks!!!!!!!!!! Enjoy Programming :)
Reference Link : http://stackoverflow.com/questions/13263507/openerp-unique-constraint
def _check_unique_insesitive(self, cr, uid, ids, context=None):
list_ids = self.search(cr, uid , [], context=context)
lst = [list_id.name.lower() for list_id in self.browse(cr, uid, list_ids, context=context) if list_id.name and list_id.id not in ids]
for self_obj in self.browse(cr, uid, ids, context=context):
if self_obj.name and self_obj.name.lower() in lst:
return False
return True
Use as following in your class :
_constraints = [(_check_unique_insesitive, <error_message>, ['<field_name>'])]
e.g : _constraints = [(_check_unique_insesitive, 'Name already exists', ['name'])]
Thanks!!!!!!!!!! Enjoy Programming :)
Reference Link : http://stackoverflow.com/questions/13263507/openerp-unique-constraint
Comments
Post a Comment
Thanks for your valuable comments.