Help

5

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

Avatar
Sreejith P

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'

Avatar
Discard
1 Answer
0
Best Answer

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 !!

Avatar
Discard