如何在odoo8中设置Integer的最小和最大验证?

时间:2016-08-18 09:38:17

标签: openerp odoo-8

_columns = {
    'product_id': fields.many2one('ims.product', 'Product', required=True),
    'qty' : fields.integer('Qty', required=True),
    'cost': fields.float('Product Cost',digits=(12,2), required=True),
    'total_cost': fields.float('Total Cost', digits=(12,2), required=True)
}

qty字段必须接受最小值10和最大值100.我能如何实现它?

1 个答案:

答案 0 :(得分:1)

定义一个函数_check_qty,它在min和max之间的qty时返回true

def _check_qty(self,cr,uid,ids):
    for product in self.browse(cr, uid, ids):
        min, max = 0,100
        min = product.min
        max = product.max
        if not min <product.qty < max: return False 
    return True
_constraints = [(_check_qty, 'Please inter other qty !', ['qty'])]