【发布时间】:2017-09-21 16:36:20
【问题描述】:
我需要有关 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
更新 我设法通过将 [] thx 添加到 dccdany 来指出这一点来解决这个问题:),并将产品变体添加到产品中
models.execute_kw(db,uid,password,'product.attribute.line','create', [{'product_tmpl_id':idProduct,'attribute_id':idAttr,'value_ids': (6,0, [idValue])}])
,但是产品变体不会自动生成,我仍然需要通过编辑手动刷新产品并保存任何想法为什么?
如屏幕截图所示,有 4 个产品变体,但右上角附近的状态仅显示 3 个变体,我在这里错过了什么吗??
【问题讨论】:
-
你试过 [(6, 0, [ids])] 吗?
-
啊,我明白了,如何更新当前的 many2many 关系?我的意思是如果我想在不替换值的情况下为 many2many 关系添加更多值,因为如果我尝试使用 [(6,0,[ids])]?它一直在替换以前的值你能举个例子吗?如何使用(0,0,{})
-
你可以只传递ID和4:[(4, ID)]
-
运气仍然没有更新我的产品变体,我正在使用此代码更新列表 models.execute_kw(db, uid, password, 'product.attribute.line', 'write',[ [7],{'value_ids':(4,idValue)}])
-
记得放[ ],。 [(4, ID)]
标签: python openerp odoo-8 xml-rpc