Odoo Help

Welcome!

This community 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.

0

Old API - how to create fields.related?

By
Dr Obx
on 3/24/16, 6:51 AM 503 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 ?

1
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,

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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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