OpenERP中设置默认值

#--------------------------------------------------
# IT goods category
#--------------------------------------------------
class goods_category(osv.osv):
    _name = "it_warehourse.goods_category"
    _description = "IT goods_category"
    _columns = {
        'name': fields.char('Name', size=100, required=True),
        'parent_id': fields.many2one('it_warehourse.goods_category', 'Parent Category', select=True),
        'child_id': fields.one2many('it_warehourse.goods_category', 'parent_id', string='Child Categories'),
        'type':fields.selection([('desktop', 'Desktop Computer'), ('notebook', 'Notebook'), ('others', 'Others')], 'Category Type'),
    }
    
    _defaults = {
        'type': lambda * a : 'desktop',
    }
    
goods_category()

其中, _defaults是设置默认值,有点类似__init__作用。

你可能感兴趣的:(open)