Odoo只读字段在onchange方法中被改变后不会保存到数据库
来源:互联网 发布:c语言 根号2 编辑:程序博客网 时间:2024/06/06 02:12
Readonly field in onchange method
If you change the value of a readonly field in onchange method, on save it will not be stored in the database. In order to do that you would need to override create/write methods where you would need to update the values dictionary with this value before creation.
For example, you would need to update the readonly field “invoice_method” the depends on the “partner_id” field. If you change its value in the onchange_partner_id method
@api.onchange('partner_id')def onchange_partner_id(self): res = super(MrpRepair, self).onchange_partner_id() self.invoice_method = self.partner_id.prepaid and 'b4repair' or 'after_repair' return res
the new value will not be stored in the database on save. Instead, you would need to extend the create method and to update the “vals” dictionary before creation
@api.modeldef create(self, vals): if vals.get('partner_id'): vals.update({'invoice_method': self.env['res.partner'].browse( vals.get('partner_id')).prepaid and 'b4repair' or 'after_repair'}) return super(MrpRepair, self).create(vals)
总结:只读字段需要根据其他字段进行onchange的时候,直接在create方法中更新字段即可。这里还需要我们测试一下,记录创建好之后,写在create方法中的方法就不会走了,是否考录需要修改再write方法里。
From:http://www.odooninja.com/readonly-field-onchange-method/
- Odoo只读字段在onchange方法中被改变后不会保存到数据库
- odoo(Openerp)如何在字段的on_change方法中动态返回domain
- 在DataGridView中修改后的数据如何保存到数据库
- 用hibernate 读取BLOB字段保存到数据库中
- 文本框中有值,属性只读,将其值保存到数据库中
- 图片保存到数据库blob字段
- odoo中怎么在数据库中直接修改翻译内容
- 读取到gridview后保存到数据库
- JS中onchange事件:域内容被改变的事件
- Odoo中一些方法
- win32 ,在edit控件中删除字符后,在保存到文件,被删字符仍在文件中
- Oracle 把字符串分割后保存到Table的一个字段中
- SQL SERVER 2008数据库表中修改字段后不能保存
- SQL Server 2008数据库表中修改字段的数据类型后,不能保存
- SQL SERVER 2008数据库的表中修改字段的数据类型后,不能保存
- 解决SQL SERVER 2008数据库表中修改字段后不能保存
- sql server数据库的表中修改一个表的字段的数据类型后,不能保存
- 解决SQL SERVER 2008数据库表中修改字段后不能保存的问题
- FFmpeg源码剖析-通用:get_input_packet()
- curl和elinks访问中遇到问题及解决办法
- python自带的sum()函数和numpy库中的sum()函数的区别
- Ant中build.xml详细部署
- Java多线程(九):Condition-线程通信更高效的方式
- Odoo只读字段在onchange方法中被改变后不会保存到数据库
- A
- unity editor 使用 aws s3 sdk
- 深入理解ios开发中的bitcode功能
- iOS开发之如何通过路由方式进行页面间的跳转
- 虚拟机/VMware Tools安装
- VC 回调函数及使用方法
- HDU
- 2017-9-17 PAT考试记