콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
5 답글
28173 화면
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)]})


아바타
취소