Skip to Content
Menu
This question has been flagged
1 Reply
3247 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"), ???

EDIT:

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(

'product.casesize',

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

}

Whatever I do still getting error wrong co-model.

What am I doing wrong ?

Avatar
Discard
Best Answer

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,

e.g.

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

Avatar
Discard