Odoo Help

Welcome!

This community 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.

2

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

By
Pravitha
on 5/14/13, 8:34 AM 8,591 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'))]}"

3

Andreas Maertens

--Andreas Maertens--
912
| 5 5 7
Finsterwalde, Germany
--Andreas Maertens--

I develop odoo8.0 modules

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( ...)
2

Francesco OpenCode

--Francesco OpenCode--
3608
| 5 7 9
Grottaglie, Italy
--Francesco OpenCode--

Italian Odoo (OpenERP) Modules Developer LINKEDIN: http://www.linkedin.com/in/francescoapruzzese

Francesco OpenCode
On 5/14/13, 8:40 AM

Use this system

https://accounts.openerp.com/forum/Help-1/question/13042

with readonly parameters instead invisible

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

Pravitha
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 5/14/13, 8:34 AM
Seen: 8591 times
Last updated: 12/4/15, 3:53 PM