Friday, 4 July 2014

Odoo/OpenERP: Custom unique name constraint with ignore case

#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

No comments:

Post a Comment

Thanks for your valuable comments.

Gmail: Download blocked file

Hi, today we are going to learn, how to download blocked file in gmail. Sometimes you see following message in gmail: and you can...