xml - 在 odoo11 中更新多个字段
问题描述
我一直在尝试更新具有相同值的多个字段,但我似乎无法找到一种方法来做到这一点。
<field name="credit_limit" readonly="1" attrs="{'invisible':[('check_credit','!=',True)]}"/>
我想更新同一个数据库 res_partner 上的 custom_credit 。有什么简单的方法可以通过 xml 来实现。我的最佳解决方案是隐藏字段,该字段将从上述字段中获取值,并在单击提交按钮时更新数据库。
新字段将是这样的,但它应该从credit_limit上面获取值。
<field name="custom_credit" readonly="1" type="hidden"/>
解决方案
有一种简单的方法可以在 odoo 表单中更新readonly="1"
或invisible="1"
字段,您必须添加属性force_save="1"
才能这样做。但是要跟踪check_credit
字段的变化,您必须编写一个@api.onchage('check_credit')
函数并使用该值来设置custom_credit
字段。其他方式可以是继承create
或write
函数,compute
在custom_credit
字段上使用属性,或使用related
属性。
推荐阅读
- android - 在数据更改时为 RecyclerView 中的单个项目设置动画
- python - discord.py - “命令”不可迭代?
- c++ - Visual Studio 调试器不再显示发生崩溃的代码行之前的代码行
- flutter - 如何在 Flutter 应用中点击复制 html 文本
- reactjs - React 组件不会在 Production Build 中呈现(在 Dev 中工作......)
- php - 如何使用数据库密码?
- python - 连接多个列表后,我如何知道某个项目属于哪个原始列表?
- iframe - 赛普拉斯脚本 - 跨域 - iFrame 不加载
- python - 递归函数上的Python AST exec“...未定义”错误
- typescript - 类/接口方法中的 TypeScript 显式“this”参数