如何在OpenERP 6中创建引用字段

时间:2012-12-03 18:24:01

标签: openerp

我正在尝试从OpenERP的web gui和字段类型创建一个字段作为参考 第一,没有更好的参考文档

第二个我想要的是当有人选择该字段时,它应该在选择时给出另一个没有发生的选项(虽然它给出了一些字段,但是第二个字段引发错误)!

它抛出一个错误对象不存在

1 个答案:

答案 0 :(得分:7)

参考字段主要用于在记录中显示不同模型的记录作为参考。例如,您创建了一个模型,无论何时创建并保存销售订单,采购订单,交货单,项目等,都应在模型中创建包含用户名,日期,某些注释等数据的新记录。因此,在此处添加一个引用字段,该字段链接到创建记录的原始记录(销售订单,采购订单等)。你可以在openerp 6中的res.request模型中找到它。

在班级中创建参考栏位

def _get_selection_list(self, cr, uid, context=None):
    #@return a list of tuples. tuples containing model name and name of the record
    model_pool = self.pool.get('ir.model')
    ids = model_pool.search(cr, uid, [('name','not ilike','.')])
    res = model_pool.read(cr, uid, ids, ['model', 'name'])
    return [(r['model'], r['name']) for r in res] +  [('','')]

_columns = {
    'ref': fields.reference(Reference', selection=_get_selection_list, size=128)
}