Odoo Help


Make a field read-only based on another field value in Openerp 7

on 5/14/13, 8:34 AM 10,179 views

Hi all,

I have a char field called my_field in Customer Reciepts (in account.voucher) form view. I want to make this readonly when the state in Journal Entries( in account.move) is posted for the corresponding entry in Customer reciepts. How can i do this in view file of Customer Reciepts using attrs="{'readonly':[('state','in',('posted'))]}"

Andreas Maertens
On 5/14/13, 8:55 AM

Additionally to Francescos Answer you can add functions to validate if a field should be visible by this:

(copied from Francescos link: https://accounts.openerp.com/forum/Help-1/question/13042/)

You can add an invisible field on your view (invisible="1") relating to a function field in your model. There you can evolve by anything you want and return a stringm bool or number and so in to evaluate if another field is visible or maybe readonly:

The View:

<field name="write_if_manager" attrs="{'readonly':['|',('is_manager', '==', 'false'),('state','not in','['draft']') ] }/>
<field name="is_manager" invisible="1"/>

The class looks like

class classname(osv.osv): 
    def _is_manager(cr, uid, ids ...
        res = {}
        for this_id in ids:
            if obj_users.has_group(cr, uid, 'MANAGER-GROUPNAME'):
                res[this_id] = manager
        return res
    _columns = {
        'is_manager':fields.function(_is_manager, type='boolean' ...
        'write_if_manager':fields.char( ...)
Francesco OpenCode
On 5/14/13, 8:40 AM

Use this system


with readonly parameters instead invisible

sir actualy i want the field to be readonly if state of account.move is 'posted'

on 5/14/13, 8:44 AM

<field name="YOUR_FIELD_NAME" attrs="{'readonly':[('state','=','posted')]}">

Francesco OpenCode
on 5/14/13, 11:11 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 5/14/13, 8:34 AM
Seen: 10179 times
Last updated: 3/1/17, 3:29 AM