Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
5 Răspunsuri
28075 Vizualizări
How to Disable edit form fields when state is done of form.

state = fields.Selection([
('draft', "Draft"),
('confirmed', "Confirmed"),
('done', "Done"),
], default='draft')

@api.multi
def action_draft(self):
self.state = 'draft'

@api.multi
def action_confirm(self):
self.state = 'confirmed'

@api.multi
def action_done(self):
self.state = 'done'
Imagine profil
Abandonează
Cel mai bun răspuns

You can add the record rule to restrict the write access when the state is Done. 

In the record rule, You add the domain_force for state is done. Then You give the permission to read only.


 <record model="ir.rule" id="no_edit_in_done_state">

           <field name="name">No Edit in done state</field>

            <field name="model_id" ref="model_your_model_name"/>

           <field name="groups" eval="[(4, ref('base.group_user'))]"/>

           <field eval="0" name="perm_unlink"/>

           <field eval="0" name="perm_write"/>

           <field eval="1" name="perm_read"/>

           <field eval="0" name="perm_create"/>

           <field name="domain_force">[('state', '=', 'done'])]</field>

   </record>

If You using this record rule, the all fields are readonly when the state is done.   

Imagine profil
Abandonează

The best solution,

if you need to edit that form later, you can add a button in which you reset the state with .sudo().

Cel mai bun răspuns

Put attrs on every fields which you don't want to let edit in edit mode after state = done.


<field name="any_field_on_form" attrs="{'readonly':[('state','=','done']}" />

Imagine profil
Abandonează
Cel mai bun răspuns

record rule best solution but doesn't work

any help ?


 <record model="ir.rule" id="no_edit_in_done_state">

<field name="name">No Edit Or Delete in Awaiting Approval state</field>
<field name="model_id" ref="model_bid_bids_screen"/>
<field name="groups" eval="[(4, ref('bid.group_workers'))]"/>
<field eval="0" name="perm_unlink"/>
<field eval="0" name="perm_write"/>
<field eval="1" name="perm_read"/>
<field eval="0" name="perm_create"/>
<field name="domain_force">[('state','=','awaiting_approval')]</field>

</record>
Imagine profil
Abandonează

Have you tried adding your module name in ref?

<field name="model_id" ref="your_module_name.model_bid_bids_screen"/>

I think I'm wrong, never mind my comment.

Cel mai bun răspuns

You can also do this in the python code itself:

field_name = fields.field_type(string='Field name', store=True, readonly=False, states={'done': [('readonly', True)]})


Imagine profil
Abandonează