OpenERP中检测写法

#--------------------------------------------------
# other resources
#--------------------------------------------------    
class goods_other_resourse(osv.osv):
    _name = 'it_warehourse.other_resourse'
    _columns = {
        'number': fields.char('Number', size=10, required=True, readonly=True, help="The number is reference goods number!"),
        'name': fields.char('Name', size=100, required=True, readonly=True),
        'color':fields.char('Color', size=50),
    }   
    
    def _check_other_resourse_id_number(self, cr, uid, ids, context=None):

        other_resourse = self.browse(cr, uid, ids)[0];
        myids = self.search(cr, uid, [('number', '=', other_resourse.number)])
        if len(myids) != 1:
            return False
        return True
        
    _constraints = [
        (_check_other_resourse_id_number, 'Number has existed in Other Resource!', ['Number']),
    ]
    
goods_other_resourse()


是通过_constraints去设置检测的。

你可能感兴趣的:(open)