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'
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
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.
The best solution,
if you need to edit that form later, you can add a button in which you reset the state with .sudo().
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']}" />
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>
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.
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)]})
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up