تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
18918 أدوات العرض

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
ديسمبر 23
91113
3
سبتمبر 21
5172
3
يناير 21
12384
Time field in odoo تم الحل
3
مارس 20
42923
1
يوليو 16
6912