0
votes

In OpenERP version 7, I need to show or hide a field in the Form View of the "Add Object" based on the values from the Parent Object.

For example, I have a field demo_field1 in sale_order. When I create a Sale Order Line, I do not want to show the field "th_weight" if the demo_field1 for the Sale Order is greater than 200.

using attrs="{'invisible': [('demo_field', '>', '200')]}" or attrs="{'invisible': [('order_id.demo_field', '>', '200')]}" shows invalid field in domain.

How to achieve this?

1

1 Answers

1
votes

I also had the same issue some time before. What i did was to add a related field in the sale_order_line and define attriute based on that related field. ie; In sale order line i defined a related field to the field demo_field1 as:

'test_field_new': fields.related('order_id', 'client_order_ref', string="Test Field", type="float")

But the related field will only be loaded at the time of saving the record. So i passed the default value of the field test_field_new from xml file as:

<field name="order_line" context="{'default_test_field_new': demo_field1}"/>

so that when i click on "Add new item" in one2many field, the value of the field demo_field1 will be loaded by default to test_field_new and i defined the attribute using the field test_field_new.

<field name="price_unit" attrs="{'invisible': [('test_field_new', '&gt;', 200)]}"/>

I am not sure this is a clean method to do...