I need to do the readonly field 'message_ids' according to a certain value of a model field
.py code:
class ModuleName(models.Model):
# Private attributes
_name = 'module.name'
_inherit = ['mail.thread']
STATE_SELECTION = [
('draft', 'Draft'),
('open', 'Open'),
('closed', 'Closed'),]
# Fields declaration
name = fields.Char(string='Name', required=True)
state = fields.Selection(string='Status', selection=STATE_SELECTION, default='draft')
.....
.xml code:
<!-- module.name form view -->
<record model="ir.ui.view" id="module_name_view_form">
<field name="name">module.name.view.form</field>
<field name="model">module.name</field>
<field name="arch" type="xml">
<form>
<header>
<field name="state" widget="statusbar" statusbar_visible="draft,open,closed"/>
</header>
<sheet>
<div class="oe_title">
<div class="oe_edit_only">
<label for="name"/>
</div>
<h1><field name="name" class="oe_inline" attrs="{'readonly': [('state', '!=', 'draft')]}"/></h1>
</div>
<!-- other fields was here -->
</sheet>
<div attrs="{'invisible': [('state', '==', 'draft')]}">
<div class="oe_chatter">
<field name="message_ids" widget="mail_thread" attrs="{'readonly': [('state', '==', 'closed')]}"/>
</div>
</div>
</form>
</field>
</record>
This code does not work for me.
Thanks
See this: https://www.scoop.it/t/learn-openerp