跳至內容
選單
此問題已被標幟
2 回覆
18818 瀏覽次數

Hello community,

How can I make a field readonly after save? It should not be editable after all.

I have try that with this, but it's not working at all.

product_reff = fields.Many2one('product.template', 'product_id', select=True)
is_created = fields.Boolean('Created')
def create(self, cr, uid, vals, context=None):
 vals['gio_is_created'] = True
 lot = super(stock_production_lot, self).create(cr, uid, vals, context=context)
 return lot


<field name="product_reff" position="attributes">
 <attribute name="attrs">{'readonly': [('is_created','=',True)]}</attribute>
 </field>


Thank you

頭像
捨棄

the answer dose not working for me, dose your problem solved?

最佳答案

hi,

<field name="product_reff" position="attributes"> <attribute name="attrs">{'readonly': [('is_created','=',True)]}</attribute>  </field>

this should works I think is is_created has a true value.

just try this also

<xpath expr='//field[@name='product_ref']' position='attributes'>

     <attribute name='attrs'>

        {'readonly': [('is_created','=',True)]}

    </attribute>

</xpath>

頭像
捨棄
最佳答案

You do not need an extra field like the `is_created`. You can use the `id` field. If the `id` is not set, the record is being created. If the `id` is set, the record has been created.

   

    {'readonly': [('id', '!=', False)]}

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
3
12月 23
90972
3
9月 21
5090
3
1月 21
12294
3
3月 20
42819
1
7月 16
6821