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.
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',
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"
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)
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`
@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`
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.