İçereği Atla
Menü
This question has been flagged
4 Cevaplar
11368 Görünümler

Please help me to understand the basic concepts of releated field in openerp 7.0 with simple examples

Avatar
Vazgeç
Best Answer

A related is simply a function field capable to retrieve by itself values from relations models, typically from many2one relation models, for this you need to specify the path to the field in the target model that you want to access using the related field. This path is in the form of a sequence of arguments for the constructor of field at the begining, the rest of the arguments that not are part of the path need to be named arguments. As every function field the related need to specify it's type and in the case when the target type is a relation one like many2one, one2many or many2many, you need to specify of the relation named value with the target model of the relation. Take this examples, we will create related fields to access fields through many2one relations of the models:

class res_example1(osv.osv):
_name = 'res.example1'
_columns = {
'name': fields.char('Name', size=64),
'code': fields.char('Code', size=64),
'value': fields.float('Value'),
}
res_example1()

class res_example2(osv.osv): 
_name = 'res.example2'
_columns = {
'name': fields.char('Name', size=64),
'example_id': fields.many2one('res.example1', string='Example 1'),
'code_example': fields.related('example_id', 'code', type='char', string='Code'),
}
res_example2()

class res_example3(osv.osv): 
_name = 'res.example3'
_columns = {
'name': fields.char('Name', size=64),
'example_id': fields.many2one('res.example2', string='Example 2'),
'value_example': fields.related('example_id', 'example_id', 'value', type='float', string='Value'),
'ref_example': fields.related('example_id', 'example_id', type='many2one', relation='res.example1', string='Example 1'),
}
res_example3()

In res.example2 model the related access to the code field of the res.example1 through it's field example_id, using this path ('example_id', 'code',...) as first parameters in the field definitions. In res.example3 model we have 2 related fields, the value_example is for access the field value in res.example1, note that res.example3 has no direct relation with res.example1, thas why the arguments for path is ('example_id', 'example_id', 'value',...). Using the relation with res.example2 and res.example2 relation with res.example3 is how res.example3 related field value_example have access to the field value of res.example1. The second related in res.example3 is for show how a related to a relation target type can be done, in this case we will map the access to the field example_id in res.example2 so we need to specify the type many2one and the target relation using the relation argument.

Hope this helps

Avatar
Vazgeç

does it the same in V8 ?

yes, you could do it using the old api or v8 api like:

nickname = fields.Char(related='user_id.partner_id.name')
Best Answer

Axel Mendoza's answer says it all, as an extra a simplified description would be:
* A related field is a link to another field stored in another model, as axel said, usually in a m2o relation field

Avatar
Vazgeç
Related Posts Cevaplar Görünümler Aktivite
2
May 22
32636
0
Mar 19
3219
0
Oca 19
4128
0
Oca 18
3307
0
Eyl 17
3687