2013-04-17 4 views
0
class deduction_registration(osv.osv): 
    _name = "bpl.deduction.registration" 
    _description = "Deduction Registration" 
    _columns = { 
     'name': fields.char('Deduction Name', size=256, required=True), 
    } 
    _sql_constraints = [('deduction_registration_name_unique', 'unique(name)', 'Deduction name already exists')] 

deduction_registration() 

Я создал выше ограничений sql для своей модели. Но он по-прежнему позволяет дублировать записи без учета регистра.OpenERP 7 _constraints

как ФПЧП и ФПЧП позволило как добавить ограничение для этого.?

+0

возможного дубликата [OpenERP Unique Constraint] (http://stackoverflow.com/questions/13263507/openerp-unique-constraint) –

ответ

2
class deduction_registration(osv.osv): 

    def _check_unique_insesitive(self, cr, uid, ids, context=None): 
     sr_ids = self.search(cr, 1 , [], context=context) 
     lst = [x.name.lower() for x in self.browse(cr, uid, sr_ids, context=context) if x.name and x.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 

    _name = "bpl.deduction.registration" 
    _description = "Deduction Registration" 
    _columns = { 
     'name': fields.char('Deduction Name', size=256, required=True), 
    } 
    _sql_constraints = [('deduction_registration_name_unique', 'unique(name)', 'Deduction name already exists')] 
    _constraints = [(_check_unique_insesitive, 'Deduction name already exists', ['name'])] 

deduction_registration() 

с этим кодом я сделал свою работу :-)

+0

Великих !!! Работал и для меня. – dirtyhandsphp