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 can i hide a field in odoo9

By
sreejith
on 10/4/16, 6:31 AM 276 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)]}"/>               

</xpath>           

</field>       

</record>
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.

Artem
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',

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

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

3 follower(s)

Stats

Asked: 10/4/16, 6:31 AM
Seen: 276 times
Last updated: 10/6/16, 10:12 AM