How to create a reference field in OpenERP 6

2019-03-30 06:40发布

I am trying to create a field from the web gui of OpenERP and field type as reference 1st there is no better docs about reference

2nd what I want is when someone selects the field it should give another option on selection which is not happening (though it is giving some field but 2nd field throws an error)!

It throws an error object does not exist

标签: openerp
1条回答
爷、活的狠高调
2楼-- · 2019-03-30 06:43

Reference fields are mainly used for showing different model's records as reference in your record. For example you have created a model such that whenever a sale order, purchase order, delivery order, project etc are created and saved, then a new record with data like user name, date, some notes should be created in your model. So here you add a reference field which link to the original record(sale order, purchase order etc) from which your record is created. You can find this in res.request model in openerp 6

To create an reference field in your class

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)
} 
查看更多
登录 后发表回答