This question has been flagged
11 Replies
17273 Views

I tried to use attrs in <page> and <group> as follows:

NOT WORKING

<group attrs="{'readonly':[('state','=','done')]}">
    <field name="field1" />
    <field name="field2" />
    <field name="field3" />
    <field name="field4" />
</group>

but readonly does not work in page and group. instead when tried with invisible, it worked.

So, should I use readonly for field level only or is there any better method?

WORKING

<group>
    <field name="field1"  attrs="{'readonly':[('state','=','done')]}" />
    <field name="field2"  attrs="{'readonly':[('state','=','done')]}"/>
    <field name="field3"  attrs="{'readonly':[('state','=','done')]}"/>
    <field name="field4"  attrs="{'readonly':[('state','=','done')]}"/>
</group>
Avatar
Discard

Have you opened an issue in the odoo tracker ? Because it would be something really practical to have...

Hello Atchuthan, I have the same problem with you. Did you solve it?

Author

@yopi, no. I set those 4 fields as read-only and not in group.

This would be very handy indeed.

Also documentation makes no mention that "Invisible" attribute is working, but not "readonly" and "required".

https://www.odoo.com/documentation/9.0/reference/views.html#structural-components

Best Answer

This would be very handy indeed.

Also documentation makes no mention that "Invisible" attribute is working, but not "readonly" and "required".

https://www.odoo.com/documentation/9.0/reference/views.html#structural-components

Avatar
Discard
Best Answer

In Default Openerp Project Module attrs readonly used in the <page> tag:-

addons/project/project_view.xml

<page string="Extra Info" attrs="{'readonly':[('state','=','done')]}">
                            <group col="4">
                                <field name="priority" groups="base.group_user"/>
                                <field name="sequence"/>
                                <field name="partner_id"/>
                                <field name="state" invisible="1"/>
                                <field name="company_id" groups="base.group_multi_company" widget="selection"/>
                            </group>
                            <group>
                                <group string="Gantt View">
                                    <field name="date_start"/>
                                    <field name="date_end"/>
                                </group>
                                <group>
                                </group>
                            </group>
</page>
Avatar
Discard
Author

yes, its available in code. But its not working in project_view

Best Answer

I have used it in my custom module

<page string="Campaign Details">
                    <field name="outdoor" widget="outdoor" attrs="{'invisible':[('type_of_activity','=','paper_media')]}" >
                    <tree string="Out Door Activity" editable="bottom">
                        <field name="sequence_no"/>
                        <field name="product_id"/>
                        <field name="places"/>
                        <field name="duration"/>
                        <field name="width"/>
                        <field name="length"/>
                        <field name="tax_id" widget="many2many_tags" domain="[('parent_id','=',False),('type_tax_use','&lt;&gt;','purchase')]"/>
                        <field name="price"/>
                        <field name="quantity"/>
                        <field name="price_subtotal"/>
                    </tree> 
                    </field>
</page>
Avatar
Discard
Author

yes, I can also use it on a single field.

I am asking how to set readonly for a group or page

Author

also only invisible works in attrs of group and page

i think you should have use this for readonly <group string="Data"> <field name="url" widget="url" attrs="{'readonly':[('type','=','binary')]}"/> </group>

Author

yes but my question regards to use of attrs="{'readonly':[domain]}" in PAGE and GROUP