Skip to Content
Menu
This question has been flagged
1 Reply
4025 Views

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


Avatar
Discard
Related Posts Replies Views Activity
0
Jun 23
1227
0
Nov 21
631
1
Mar 21
7629
2
Dec 20
2069
0
Feb 20
1316