如何在文件中添加Many2One数据

时间:2019-09-16 13:27:06

标签: odoo odoo-12

我有一些相互依赖的模型,它们之间具有Many2One和One2Many关系。

我已经设置了所有视图,但是现在我要通过数据文件添加数据以测试所有内容,发现我不知道如何添加这些记录。

我应该在基本声明记录的同时保持关系值为null的运行,然后再更新具有关系的记录吗?

此外,关系字段的值应该是多少?数组之类的东西?

1 个答案:

答案 0 :(得分:0)

您始终可以将内置模块的演示文件和数据文件用作参考

您可以看到here query.ToListAsync().Resultcategory_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')函数,在加载数据文件时进行评估,它采用相关字段的XML recordID (有时您可能需要使用外部ID,例如,在这种情况下,记录的外部ID为python

参考文献:1 2