Odoo Help


how can i hide a field in odoo9

Sreejith P
on 10/4/16, 6:31 AM 2,351 views

i would like to create a module which disable 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 RuntimeError: maximum recursion depth exceeded while calling a Python object

<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':[('hide_discount', '=', False)]}"/>               



in my .py

class DiscountField(models.Model):
 _inherit = 'account.invoice.line'

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

discount = fields.Float(string='Discount (%)')

hide_dis = fields.Boolean(related='record.discount_bool')

record = fields.Many2one('account.invoice') - already exists as 'invoice_id'

<field name="discount" attrs="{'invisible':[('hide_discount', '=', False)]}"/> I do not see where 'hide_discount' is.

on 10/4/16, 8:00 AM

An invoice head and Invoice lines are all in the same view. So I think you need not any modification in 'account.invoice.line'. Add 'hide_discount' field to 'account.invoice' and modify the 'account.invoice_form',

on 10/4/16, 8:07 AM

For starters I think you have a typo:

On your view the invisible attrs logic uses "hide_discount"

but your related field is only "hide_dis"

Mai Ecarde
on 10/4/16, 10:55 AM

You will also need to add the field "hide_dis" to the tree. Add the following before the discount field:

<field name="hide_dis" invisible="True"/>

Also note that if this works the column will still be visible on the tree (only the values are hidden)

Mai Ecarde
on 10/4/16, 11:00 AM

sorry its a typo.

@Artem the field is hide_discount and is used to take the value from account.invoice but it worked with invoice_id,but the column id still there and but values are hidden. By adding `hide_discount` field to 'account.invoice' how can i create the view in `account.invoice.line`

Sreejith P
on 10/5/16, 2:01 AM

@Mai Ecarde you are right the column will still be visible on the tree (only the values are hidden). How can i hide the column when discount_bool is false in `account.invoice`

Sreejith P
on 10/5/16, 2:05 AM

You could try having the field 'invoice_line_ids' defined twice in the view with opposite visibility on hide discount. One with the discount column and one without. I think this might work due to only one instance of the field being visible.... although I tend to get bad results from having a field in a view twice. If this doesn't work I am not sure there is a simple way.

Mai Ecarde
on 10/6/16, 10:16 AM
Jesni Banu
On 3/4/17, 4:50 AM

You can hide discount field as follow.

<xpath expr="//field[@name='invoice_line_ids']/tree/field[@name='discount'] position="attributes">                  
     <attribute name="attrs">{'invisible': [('hide_discount', '=', False')]}</attribute>              

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.


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

3 follower(s)


Asked: 10/4/16, 6:31 AM
Seen: 2351 times
Last updated: 3/4/17, 5:19 AM