Odoo Help


Old API - how to create fields.related?

Dr Obx
on 3/24/16, 6:51 AM 1,097 views

Guys I want use one of the fields from product_template in my module.

And it seems that field related will/should be the best option. How should it look like if I would like to use field named product_size_id from product_template (it's custom field but anyway, if I would like to use any other existing field like .... sale_ok)?

'size': fields.char(related='product_template.product_size_id', string="Size/PT"), ???


Got it,

'size': fields.related('product_template','product_casesize_id', string="Size/PT", type="char"),

But what if it is many2one field and I would like to use whole content of this table ?

class product_casesize(orm.Model):

_name = 'product.casesize'

_columns = {

'name': fields.char('Case size'),


class product_template(orm.Model):

_inherit = 'product.template'

_columns = {

'product_casesize_id': fields.many2one(


'Case size', help='Select size of the case.', ondelete='restrict'),


Whatever I do still getting error wrong co-model.

What am I doing wrong ?

Julio Serna
On 3/30/16, 1:02 AM

First, to use fields.related you must have in your custom model one field relation to 'product.template',

if 'size' field is into class  product_casesize() also you need one field relation to product.template to begin iterating into product_template() in your case 'product_template' must be a field in your model,


class product_casesize(orm.Model):

_name = 'product.casesize'

_columns = {

'name': fields.char('Case size'),

'product_template': fields.many2one('product.template'),

sale_ok_custom: fields.related('product_template', 'sale_ok',  type="boolean"),

again, if 'size' is field into product_casesize() this field definition , 

'size': fields.related('product_template','product_casesize_id', string="Size/PT", type="char"),
 has no sense because you are back to your own model

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 3/24/16, 6:51 AM
Seen: 1097 times
Last updated: 3/31/16, 8:15 AM