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

how to hide a field in another model when a boolean field is false in odoo9

By
sreejith
on 10/1/16, 3:13 AM 155 views

i would like to create a module which hide a field `discount` in `account.invoice.line` if a boolean field `discount_bool` is set to false in `account.invoice`. when i tried below mentioned code i got an error raise TypeError("Type of related field %s is inconsistent with %s" % (self, field))TypeError: Type of related field account.invoice.line.fd is inconsistent with account.invoice.discount_bool

in xml

<record id="discount_invoice_lines_ids" model="ir.ui.view">

                <field name="model">account.invoice</field>

                <field name="name">discount_invoice_lines</field>

               <field name="inherit_id" ref="account.invoice_form"/>

                <field name="arch" type="xml">

                    <xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='discount']" position="replace">

                        <field name="discount" attrs="{'invisible':[('discount_bool', '!=', False)]}"/>

                    </xpath>

               </field>

</record>


in py

orderline = fields.Many2one('account.invoice') 

discount = fields.Char(string='Discount (%)', default=0.0)

fd = fields.Char(related='orderline.discount_bool'

0

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 10/1/16, 5:26 AM

Hi,

The error in the .py file not in the attrs expr. 

fd = fields.Char(related='orderline.discount_bool'

you defined the fd with type Char which I think it should be with type Boolean !!

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: 10/1/16, 3:13 AM
Seen: 155 times
Last updated: 10/1/16, 5:26 AM