1
votes

I would like to make a many2one field invisible when called by 'add an item' in the One2many view, for exemple :

parent view :
   Name = 'this is One2many field'
   value 1 = 
   value 2 :  add an item

child view :
   Parent Name = 'this is Many2one field'
   value 1 = ....

and when i click on 'add an item' i'd like to get the folowing view :

child view :
   value 1 = ...

I tried setting attrs="{'invisible':[('parent_id', '!=', False)]}" in the child view but this is always true because the parent fields are not created yet. Any idea ?

2

2 Answers

2
votes

There is very simple way to achieve this by defining inline form view for that one2many field.

Here is an example for your reference.

<field name="one2many_field_name">
    <tree>
        <field name="field1" />
        <field name="field2"  />
        <field name="field3"  />
    </tree>
    <form>
        <field name="field1" invisible="1" />
        <field name="field2"  />
        <field name="field3"  />
    </form>
</field>

While you click on "Add an item" it will render form view which is defined inline and if there is no inline view defined then it will take form view which you have created externally.

So, that way you can define inline view for many2many / one2many fields, in that manner you can define behavior of any fields directly.

1
votes

You can achieve it by setting context in one2many field in parent form view.

I will explain you by example. placement_line is the parent view one2many field. In that set the context like below code.

<field name="placement_line" context="{'one2many':True}" /> 

Here, student_id is the manyone child form view field. See the below code.

<field name="student_id" invisible="context.get('one2many')"/>

By settings like above code in your parent form and child form you can invisible child field(many2one) when child form open from 'add an item' in the One2many view.