如何允许用户提交问卷后编辑问卷答案?
允许提交后的问卷答案编辑解决方案
1. 开启问卷核心编辑开关
首先确保问卷本身允许编辑:打开目标问卷的表单页面,切换到「设置」标签,勾选允许已提交的回答编辑选项。这是基础前提,未开启此开关的话,后续权限设置都不会生效。
2. 完善权限组与记录规则
你之前创建的group_survey_editors组缺少必要的权限关联,需补充以下配置:
- 给该组添加
survey.user_input模型的写入权限(Write Access),编辑问卷答案本质是修改user_input记录; - 创建针对
survey.user_input模型的精准记录规则,替换你之前的泛规则:<record id="survey_user_input_edit_done_rule" model="ir.rule"> <field name="name">Allow editing done survey answers</field> <field name="model_id" ref="survey.model_survey_user_input"/> <field name="groups" eval="[(4, ref('your_module.group_survey_editors'))]"/> <field name="domain_force">[('state', '=', 'done')]</field> <field name="perm_write" eval="True"/> </record> - 将需要编辑权限的用户添加到
group_survey_editors组中。
3. 添加前端编辑按钮
Odoo默认不会给已提交的问卷显示编辑按钮,需通过视图继承添加:
<record id="survey_user_input_form_view_inherit" model="ir.ui.view"> <field name="name">survey.user_input.form.inherit</field> <field name="model">survey.user_input</field> <field name="inherit_id" ref="survey.user_input_form_view"/> <field name="arch" type="xml"> <xpath expr="//field[@name='state']" position="after"> <button name="action_set_to_in_progress" string="Edit Answer" type="object" attrs="{'invisible': [('state', '!=', 'done')]}"/> </xpath> </field> </record>
该按钮调用Odoo内置的action_set_to_in_progress方法,可将问卷状态从done切换回in_progress,允许用户重新编辑。
4. 验证测试
用加入目标权限组的用户登录系统,打开一条已提交(状态为done)的问卷答案,确认能看到「Edit Answer」按钮,点击后可修改答案,提交后状态自动回到done。
内容的提问来源于stack exchange,提问作者Ping Feliciano
相关产品推荐
相关产品推荐

