Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
18683 Weergaven

Hello,

Im trying to remove/hide the "Add a line" link and the 'delete' button in one2many tree view base on the condition of the state. 

Ex: They just appear in the state: 'draft. When changing the state, they will be hidden/remove!

model_b.py :

name = fields.Many2one('hr.employee')

o_2_m = fields.One2many('model.a', 'keya')

state = fields.Selection([

            ('draft', 'DRAF'),

            ('confirm', 'CONFIRMED'),

            (cancel', 'CANCEL'),

            ],default='draf')


model_a.py :

name = fields.Many2one('hr.employee')

keya = fields.Many2one('model.b')

num_1 = fields.Float('Number')

ref_1 = fields.Char('Reference')


I'd tried to set 'readonly' for all related field in file XML:

<notebook>

                            <page name="Want_to_hide_button" string="Test">

                                <field name="o_2_m" options="{'no_create': True}" widget='many2many'>

                                    <tree string="ABC DEF">

                                        <field name="state" invisible="1"/>

                                         <field name="name" attrs="{'readonly':[('state' , '!=', 'draft')]}"/>

                                         <field name="num_1" widget="monetary" attrs="{'readonly':[('state' , '!=', 'draft')]}"/>

                                         <field name="ref_1" attrs="{'readonly':[('state' , '!=', 'draft')]}"/>

                                         <field name="currency_id" invisible="1"/>

                                    </tree>

                                </field>

                           </page>

</notebook>


But it still not worked.


Please help.

Thank you!


Avatar
Annuleer
Beste antwoord

Hi ,

    You logic is correct but you need not give that to all the fields in the one2many tree view,

You can define that in the field definition itself in py file like,

o_2_m = fields.One2many('model.a', 'keya', string='One2many', readonly=True, states={'draft': [('readonly', False)]}, copy=False)

or 

In xml, you can give that

<field name="o_2_m" attrs="{'readonly': [('state', '!=', 'draft')]}" widget='many2many'>

Thanks

Avatar
Annuleer
Auteur

Yes, I got it. Thank you, Karthikeyan

Gerelateerde posts Antwoorden Weergaven Activiteit
1
apr. 25
3845
3
mrt. 21
5173
1
jun. 17
6638
1
okt. 23
5022
0
feb. 21
3494