When using a related field you have to first select which field to be related. For example I'm creating a new module for adding student details. Here the student is actually the partner. So _rec_name='partner_id'
is taken.In res.partner
you may have seen the ref
field. The value in the ref
field is taken as the internal_number
for the student module.
So what we do here is
class student(osv.osv):
_name='student'
_rec_name='partner_id'
_columns ={
'partner_id':fields.many2one('res.partner','Name'),
'internal_number':fields.related(
'partner_id',
'ref',
type='char',
size=16,
string='Internal Number',
),
}
If the field we want to show as related field is a selection field, then you have to provide type='selection'
, and selection=[(case1,case1),(case2,case2),...]
, a list of tuples. If it is a many2one field, then type='many2one'
and relation='model_name'
.