Odoo Help

0

How to access a field of another model in a button with the attrs attribute?

By
James Ford
on 3/10/16, 11:55 AM 951 views

How do i access the field product_id.product_tmpl_id.type from the sale.order.linemodel.

I have the following button in the xml view:

button name="print_report" string="Print" type="object" icon="gtk-print" attrs="{'invisible':[('product_id.product_tmpl_id.type', '!=', 'product')]}"/>.

With this statement , Odoo shows me the following error:

Uncaught Error: Campo desconocido product_id.product_tmpl_id.type en el dominio [["product_id.product_tmpl_id.type","!=","product"]]

I appreciate your help. Thank you

can u please update where have you taken that button, is it under 'order line' tree view or outside?
if it is outside the tree view,then try keeping it in...

Pawan
on 3/11/16, 6:07 AM
1
Wilbert Tan
On 3/10/16, 11:11 PM

Hi James, try to make a field related first in the sale.order.line model

Note that this code is in v8 odoo

#declare the selection first

PRODUCT_TYPE = [('consu', 'Consumable'),('service','Service'),('product', 'Product')]

#declare the field

field_related = fields.Selection(PRODUCT_TYPE, related='product_id.product_tmpl_id.type', string='Fields used for attrs', readonly=True)
#on the view.xml
button name="print_report" string="Print" type="object" icon="gtk-print" attrs="{'invisible':[('field_related', '!=', 'product')]}"/>.


Regards,

Hi @WilbertTan Odoo I still continued showing me the same message : Campo desconocido field_related en el dominio [["field_related","!=","product"]] I did exactly what you said , but still continues showing me the same error. What else can I do? Thanks.

James Ford
on 3/11/16, 8:46 AM

Hi James, I am not sure about your error. I've tried on my local and it works as intended. Please paste your code and I'll check. Make sure you check the wording too.. In case any typo. Thanks,

Wilbert Tan
on 3/13/16, 10:00 PM

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.

Register

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)

Stats

Asked: 3/10/16, 11:55 AM
Seen: 951 times
Last updated: 3/10/16, 11:11 PM