Skip to Content
Menu
This question has been flagged
4 Replies
10713 Views

Hi, 

I have 2 models:


class ProjectTask (models.Model): # project_task.py

_inherit = "project.task" 

    task_line_ids = fields.One2many('project.task.line','task_id',string="Articles")

state = fields.Selection((('draft','Draft'),('open','In progress'),('done','Done'),('cancel','Cancelled')), default = 'draft', string='Status', required="True")

  @api.multi

def action_draft(self):

return self.write({'state': 'draft'})

@api.multi

def action_open(self):

return self.write({'state': 'open'})

@api.multi

def action_done(self):

return self.write({'state': 'done'})

@api.multi

def action_cancel(self):

return self.write({'state': 'cancel'})


class ProjectTaskLine(models.Model):

_name = 'project.task.line'


quantity = fields.Float("Quantity")

price_unit = fields.Float("Unit Price")

product_id = fields.Many2one('product.product', string='Article')

task_id = fields.Many2one('project.task')

progress = fields.Float('Progress') 


in the project_task.xml

 <xpath expr="//form/sheet/notebook/page[@name='description_page']" position="before">

<page string="Articles">

<field name="task_line_ids">

<tree string="Batchs Order Lines" editable="bottom">

<field name="product_id" />    

<field name="quantity"/>

<field name="price_unit"/>

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

</tree>

</field>

</page>

</xpath>


I want to hide the column "progress" in the o2m field when the state = 'draft',but i get this message error : Uncaught Error: QWeb2 - template['ListView.row']: Runtime Error: Error: Unknown field state in domain [["state","in","draft"]]

How can i do to solve it please ?

Thanks




Avatar
Discard
Best Answer

In OdooV11,

It is possible with column_invisible where you can mention condition based on state of parent model (parent.state).

Example : qty_delivered field of sale.order.line

<field name="qty_delivered" attrs="{'column_invisible': [('parent.state', 'not in', ['sale', 'done'])], 'readonly': [('qty_delivered_updateable', '=', False)]}"/>

In OdooV10,

You can not hide field conditionally in tree/list view, you can invisible but that should be fixed for all data not conditionally.

I am not sure but you can achieve this thing by using invisible with context.

Example : qty_delivered field of sale.order.line

<field name="qty_delivered" invisible="context.get('hide_sale')" attrs="{'readonly': [('qty_delivered_updateable', '=', False)]}"/>

Avatar
Discard
Best Answer

Hello,

try with this, maybe it works.

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

Thanks

Avatar
Discard
Author

I tried it already and it didn't work, Thanks.

Best Answer

Try this

attrs="{'column_invisible': [('parent.state','=', 'draft')]}"

Avatar
Discard