odoo - 如何在文件中添加 Many2One 数据
问题描述
我有一些相互依赖的模型,它们之间存在 Many2One 和 One2Many 关系。
我已经设置了所有视图,但是现在我正在通过数据文件添加数据以测试我发现的所有内容,但我不知道如何添加这些记录。
我是否应该在基本上声明记录的同时将关系值保持为空,然后稍后用关系更新记录?
此外,关系字段的值应该是什么?一个数组还是什么?
解决方案
您可以随时使用内置模块的演示和数据文件作为参考
如您所见,这里 category_ids
是Many2many
字段(同样适用于one2many
字段)
<field name="category_ids" eval="[(6, 0, [ref('employee_category_2')])]"/>
要了解eval
属性的值,请阅读以下内容:
(0, 0, { values }) link to a new record that needs to be created with the given values dictionary
(1, ID, { values }) update the linked record with id = ID (write *values* on it)
(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
(4, ID) link to existing record with id = ID (adds a relationship)
(5) unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)
对于其ref
值中的函数(即这部分ref('employee_category_2')
),它python
是在加载数据文件时评估的函数,它采用相关字段的 XML 记录 ID(有时您可能需要使用外部 ID - 例如在本例中为外部 ID记录是hr.employee_category_2
)
推荐阅读
- sql-server - 关于 xp_cmdshell 的信息
- python - 在python中有特殊字符的列中
- javascript - 如何检查 DOM 中是否存在 canvas 元素?
- c# - Transform.parent 无法访问祖父母
- azure - 立即取消配置用户,而不是 30 天软删除
- batch-file - 在批处理脚本中从文本文件中添加数字
- reactjs - React.js/Typescript:如何渲染文件夹中的图像以及使用 url 上传的图像?
- javascript - 如何将每 100 条记录中的睡眠/延迟添加到 w2ui 网格?
- php - 如何在 laravel 中使用 Maatwebsite 包连接两个表并通过 excel 导入数据?
- logging - 在 wso2 api 管理器中记录应用程序名称以及 api 调用的其他信息