gpt4 book ai didi

插入many2many odoo(前openerp)

转载 作者:行者123 更新时间:2023-12-03 10:49:21 25 4
gpt4 key购买 nike

我正在尝试将值插入到 odoo(前 OpenERP)中的 many2many 或 one2manhy 关系表中。你知道如何做到这一点吗?

最佳答案

这是来自 stock module 的示例:

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() ,没有什么可以替代的。
完整的选项列表在 documentation for the osv class 中.

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 }) 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)

关于插入many2many odoo(前openerp),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9377402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com