Odoo中点击Copy Notes按钮后填充Conclusion字段的实现问题咨询
Odoo问题:点击Copy Notes按钮无法自动填充Conclusion字段
需求与问题
- 需求:点击Copy Notes按钮后,自动填充Conclusion字段
- 问题:已尝试在方法返回数据中使用
value属性,但未达到预期效果
相关代码
@api.multi def copy_notes(self): notes = "" if self.uuid_v4 == 'e3d2e0c7-ba64-4522-abf3-9befcf2bdacc': if self.physical_examination_id.id: notes = "Physical Examination" notes = notes + ("\n" if notes and self.physical_examination_id.eyes_remark else "") # 此处为其他无关拼接逻辑 self.note = notes else: raise ValidationError(_("This exam cannot copy notes")) return { 'value': {'note': notes}, 'type': "ir.actions.do_nothing", }
界面截图

问题分析与解决方法
- 字段名称不匹配:代码中操作的是
note字段,但需求是填充Conclusion字段,需确认目标字段的实际数据库名称(如conclusion),将代码中所有note替换为对应字段名。 - 字段赋值方式问题:Odoo中直接赋值
self.note = notes在部分场景下无法触发前端视图刷新,建议改用self.write()方法更新字段,确保数据持久化同时同步到前端界面。 - 返回值逻辑优化:使用
self.write()更新字段后,无需再返回value属性,直接返回ir.actions.do_nothing即可,前端会自动刷新表单数据。
修改后的示例代码:
@api.multi def copy_notes(self): notes = "" if self.uuid_v4 == 'e3d2e0c7-ba64-4522-abf3-9befcf2bdacc': if self.physical_examination_id.id: notes = "Physical Examination" if notes and self.physical_examination_id.eyes_remark: notes += "\n" # 此处为其他无关拼接逻辑 # 替换为目标字段名,例如conclusion self.write({'conclusion': notes}) else: raise ValidationError(_("This exam cannot copy notes")) return {'type': 'ir.actions.do_nothing'}
内容的提问来源于stack exchange,提问作者strike_noir
相关产品推荐
相关产品推荐

