插入 Many2many Odoo(前 OpenERP) [英] Insert into Many2many Odoo (former OpenERP)
问题描述
我正在尝试将值插入到 Odoo(前 OpenERP)中的 Many2many
或 One2many
关系表字段中.你知道怎么做吗?
I'm trying to insert values into a Many2many
or One2many
relation table field in Odoo (former OpenERP). Do you have any idea how to do this?
推荐答案
这是一个来自 库存模块:
invoice_line_id = invoice_line_obj.create(cursor, user, {
'name': name,
'origin': origin,
'invoice_id': invoice_id,
'uos_id': uos_id,
'product_id': move_line.product_id.id,
'account_id': account_id,
'price_unit': price_unit,
'discount': discount,
'quantity': move_line.product_uos_qty or move_line.product_qty,
'invoice_line_tax_id': [(6, 0, tax_ids)],
'account_analytic_id': account_analytic_id,
}, context=context)
self._invoice_line_hook(cursor, user, move_line, invoice_line_id)
invoice_line_tax_id
字段是多对多关系,(6, 0, tax_ids)
表示用 中的记录替换任何现有记录tax_ids
.因为您正在调用 create()
,所以没有什么可以替换的.
The invoice_line_tax_id
field is a many-to-many relationship, and the (6, 0, tax_ids)
means to replace any existing records with those in tax_ids
. Because you're calling create()
, there's nothing to replace.
完整的选项列表在 osv 类的文档.
对于 many2many 字段,需要一个元组列表.这是接受的元组列表,以及相应的语义
For a many2many field, a list of tuples is expected. Here is the list of tuple that are accepted, with the corresponding semantics
(0, 0, { values })
链接到需要使用给定值字典创建的新记录
(0, 0, { values })
link to a new record that needs to be created with the given values dictionary
(1, ID, { values })
用 id = ID 更新链接记录(在上面写 values)
(1, ID, { values })
update the linked record with id = ID (write values on it)
(2, ID)
删除并删除 id = ID 的链接记录(在 ID 上调用 unlink,这将完全删除对象,以及指向它的链接)
(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)
切断与id = ID 的链接记录的链接(删除两个对象之间的关系但不删除目标对象本身)
(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)
链接到 id = ID 的现有记录(添加关系)
(4, ID)
link to existing record with id = ID (adds a relationship)
(5)
取消所有链接(如对所有链接记录使用 (3,ID))
(5)
unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs])
替换链接的 ID 列表(例如对 ID 列表中的每个 ID 使用 (5) 然后 (4,ID))
(6, 0, [IDs])
replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)
这篇关于插入 Many2many Odoo(前 OpenERP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!