我需要 XMLRPC 方面的帮助,我正在使用 python,我正在尝试创建产品变体,并且我需要为字段 Many2many 分配值,这是我的代码
idProductLineAttributeLine =
models.execute_kw(db,uid,password,'product.attribute.line','create',
[{'product_tmpl_id':idProduct,'attribute_id':idAttr,'value_ids': (6,0,
[idValue])}])
如果我分配普通字段,一切都会正常工作,但是当涉及到many2many字段或one2many字段时,它会显示这样的箭头
in __dump\nTypeError: cannot marshal <type 'builtin_function_or_method'> objects\n", "message": "cannot marshal <type 'builtin_function_or_method'> objects", "name": "exceptions.TypeError", "arguments": ["cannot marshal <type 'builtin_function_or_method'> objects"]}}}
我做错了什么?请帮助我:),提前谢谢
在odoo Essential一书中,它说我也必须使用这个来分配many2many值或one2many值,但仍然没有运气
(0,_ ,{' field': value}): This creates a new record and links it to this one
(1, id,{' field': value}): This updates values on an already linked record
(2, id,_): This unlinks and deletes a related record
(3, id,_): This unlinks but does not delete a related record
(4, id,_): This links an already existing record
(5,_,_): This unlinks but does not delete all linked records
(6,_,[ ids]): This replaces the list of linked records with the provided list
已更新 我设法通过向 dcccdany 添加 [] thx 来指出这一点来解决这个问题:),并将产品变体添加到产品
models.execute_kw(db,uid,password,'product.attribute.line','create', [{'product_tmpl_id':idProduct,'attribute_id':idAttr,'value_ids': (6,0, [idValue])}])
,但是产品变体不会自动生成,我仍然需要通过编辑并保存来手动刷新产品,知道为什么吗?
如屏幕截图所示,有 4 个产品变体,但右上角附近的状态仅显示 3 个变体,我在这里错过了什么吗?
最佳答案
在上面的代码中,您只是添加新的product.attribute.line。从技术上讲,odoo 将创建新的属性行,但是当调用产品模板写入方法时,系统将调用 create_variant_ids 方法并创建新的变体。
以下是创建或更新变体的最简单方法。
models.execute_kw(db,uid,password,'product.attribute.line','create', [{'product_tmpl_id':idProduct,'attribute_id':idAttr,'value_ids': (6,0, [idValue])}])
models.execute_kw(db,uid,password,'product.template','write',{'active':True})
当您调用产品模板写入方法时,系统将调用create_variant_ids方法。
这可能对你有帮助。
关于python - Odoo 8 Python 如何分配Many2many或one2many XMLRPC创建对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43597524/