Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
3 Risposte
15871 Visualizzazioni

Hello,

How to make specific field read-only after saving the record? i.e. When I edit the record that field should be read-only

Thanks

Avatar
Abbandona
Risposta migliore

Hello Jagdish,

> You can try this better and optimised way to make any field read only after saving a record,

> In your XML file please add 'attrs' on relevant field as below,

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


Thanks.


Avatar
Abbandona

This answer is way better

attrs no longer used since 17.0
Anyone know a way that works for 17.0?

Risposta migliore

you have to do this one

add a boolean field in your model like

_columns = {
        'is_created' : fields.boolean('Created')
    }

and in xml add attribute for the field to be made readonly, like,

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

and override create function in your model, like

def create(self, cr, uid, vals, context=None):
        vals['is_created'] = True
        lot = super(stock_production_lot, self).create(cr, uid, vals, context=context)
        return lot
Avatar
Abbandona
Autore

Thanks for Ans.

Post correlati Risposte Visualizzazioni Attività
2
lug 25
486
1
mar 25
1342
0
nov 24
1518
1
ott 24
2366
0
giu 24
1562