1
votes

I have this class: project.task that has this field:

state = fields.state = fields.Selection([ ('draft', 'Draft'),
                                          ('sent', 'In progress')], default='draft')
task_line_ids = fields.One2many('project.task.line','task_id',string="Articles")

And in project.task.line class I have this line:

progress = fields.Float()

In my xml code now I have:

<record name="task_form_view" model="ir.ui.view">
    <field name="name">Task Form View</field>
    <field name="model">project.task</field>
    <field name="arch" type="xml">
    <form>
    <header>
        <field name="state" widget="statusbar"/>
    </header>
        ....
    <notebook>
          <page name="Lines">
              <field name="task_line_ids">
                  <tree string="Tasklines" editable="bottom"> 
                      <field name="product_id" /> 
                      <field name="description"/> 
                      <field name="um_id"/> 
                      <field name="progress" />              
                  </tree> 
              </field>  
         </page>
    </notebook>
  </form>
</field></record>

Now what I want is that the field named progress inside tree view should be invisible when state is draft. I changed progress field like this:

 <field name="progress"  attrs="{'invisible': [('state','=','draft')]}" />

But it doesn't work. I got this error: Error: Unknown field state in domain [["state","=","draft"]]

I got the same error when I tried this code:

<field name="progress"  attrs="{'invisible': [('task_id.state','=','draft')]}" />
2

2 Answers

1
votes

use this:

<field name="progress" attrs="{'column_invisible':[('parent.state','in', 
['draft'])]}"/>  

in xml:

 <notebook>
      <page name="Lines">
          <field name="task_line_ids">
              <tree string="Tasklines" editable="bottom"> 
                  <field name="product_id" /> 
                  <field name="description"/> 
                  <field name="um_id"/> 
                  <field name="progress" attrs="{'column_invisible': 
                  [('parent.state','in',['draft'])]}"/>               
              </tree> 
          </field>  
     </page>
</notebook>
0
votes

I think on class "project.task.line" you need fields state = fields.Selection([ ('draft', 'Draft'),('sent', 'In progress')], related="task_id.state"). Because you use fields state current not in class "project.task.line", it's class "project.task".