class myModel(models.Model):
_name = 'my.model'
state = fields.Selection(selection=_STATES, string='Status', index=True, track_visibility='onchange',required=True, copy=False, default='draft')
my_model_line = fields.One2many('my.model.line', 'model_id')
another model:
class MyModelLine(models.Model):
_name = 'my.model.line'
name = fields.Char(string='Name')
quantity = fields.Integer(string='Quantity', required=True, default=1)
remarks = fields.Text(string='Description')
my_model_id = fields.Many2one('my.model', 'My Model')
my_model.xml
<field name="my_model_line" attrs="{'readonly': [('state','not in', ('draft'))]}">
<tree string="My model Lines" editable="bottom">
<field name="name"/>
<field name="quantity"/>
<field name="remarks"/>
<button name="open_new_view" type="object" string="Add" class="oe_highlight"/>
<button icon="terp-face-plain" name="test" type="object" string="Add" class="oe_highlight"/>
</tree>
</field>
I want to hide my.model.line moel remarks field and Add button field depend on my.model status. For example hide fields if is my model status is approved.
As I understand, I can't use invisible attribute with domain in my my_model.xml because my.model.line do not have state field. Maybe there are any solutions to do that?
I was thinking to create status field in my.model.line object ant change it status depend on my.model status.
Also I was trying like this:
<field name="remarks" attrs="{'invisible': "[('my_model_id .state', '=', 'approved')]"}"/>
But then I got an error: "Unknown field my_model_id.state in domain"