Please help me to understand the basic concepts of releated field in openerp 7.0 with simple examples
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Kế toán
- Tồn kho
- PoS
- Project
- MRP
Câu hỏi này đã bị gắn cờ
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
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')
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
Bạn có hứng thú với cuộc thảo luận không? Đừng chỉ đọc, hãy tham gia nhé!
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 5 22
|
32632 | ||
|
0
thg 3 19
|
3216 | ||
|
0
thg 1 19
|
4122 | ||
|
0
thg 1 18
|
3306 | ||
|
0
thg 9 17
|
3687 |