تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
5 الردود
28113 أدوات العرض
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'
الصورة الرمزية
إهمال
أفضل إجابة

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)]})


الصورة الرمزية
إهمال