You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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",
        }

界面截图

界面截图

问题分析与解决方法

  1. 字段名称不匹配:代码中操作的是note字段,但需求是填充Conclusion字段,需确认目标字段的实际数据库名称(如conclusion),将代码中所有note替换为对应字段名。
  2. 字段赋值方式问题:Odoo中直接赋值self.note = notes在部分场景下无法触发前端视图刷新,建议改用self.write()方法更新字段,确保数据持久化同时同步到前端界面。
  3. 返回值逻辑优化:使用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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.17 16:12:44