OE开发路第一个例子记录

类定义

class okgj_logistics_car(osv.osv):
    _name = 'okgj.logistics.car'  #类名
    _description = 'Logistics Car' #类描述
    _columns = {   #定义字段
        'name':fields.char(u'编号', size=16, required=True),
        'car_code':fields.char(u'车牌号', size=32, required=True),
        'driver':fields.char(u'司机姓名', size=16, required=True),
        'driver_phone':fields.char(u'电话号码', size=16, required=True),
        'start_time': fields.date(u'合作日期'),
        'active': fields.boolean(u'启用'),
        'warehouse_id':fields.many2one('stock.warehouse', u'物流中心',),
    }
    
    _defaults = {   # 定义默认值
        'active': True,
        'start_time': time.strftime('%Y-%m-%d'),
    }

    _order = 'name desc' # 按编号降序

okgj_logistics_car()  #结束类定义

 

 

name_get

 

# openerp中每个类都有一个get_name()方法, 
# 或者在类内用代码实现这个方法, 或者默认继承父类中的这个方法。 
# 它的签名为 name_get(self, cr, uid, ids, context=None)
# 其中ids为要查询记录的id号, 其数据类型为list。 

   def name_get(self, cr, uid, ids, context=None):
        if isinstance(ids, (list, tuple)) and not len(ids):
            return []
        if isinstance(ids, (long, int)):
            ids = [ids]
        reads = self.read(cr, uid, ids, ['car_code','driver'], context=context)
        res = []
        for record in reads:
            if record['car_code']:
                newname = record['car_code'] +' / '+ record['driver']
            else:
                newname = record['driver']
            res.append((record['id'], newname))
        return res

 

你可能感兴趣的:(例子)