gpt4 book ai didi

python - 错误: dictionary update sequence element #0 has length 3; 2 is required

转载 作者:行者123 更新时间:2023-11-30 23:16:56 33 4
gpt4 key购买 nike

当执行 onchange...() 函数时,我收到错误:

File "/opt/odoo/odoo/openerp/models.py", line 5652, in _onchange_eval
result.setdefault('domain', {}).update(method_res['domain'])
ValueError: dictionary update sequence element #0 has length 3; 2 is required

这是我的代码。我认为错误与域有关:

def onchange_template_id(self, cr, uid, ids, id, context=None):
print "\n\n on change template global_template_id ", global_template_id
bom_ids = []
pd_ids = []
product_complete = []
ptemplid = global_template_id
mbl_obj = self.pool.get('mrp.bom.line')
id_s = mbl_obj.search(cr, uid, [('product_id', '=', ptemplid)])
for rec in mbl_obj.browse(cr, uid, id_s, context=context):
bom_ids.append(rec.bom_id.id)
mb_obj = self.pool.get('mrp.bom')
for rec in mb_obj.browse(cr, uid, bom_ids, context=context):
pd_ids.append(rec.product_id.id)
pp_obj = self.pool.get('product.product')
for rec in pp_obj.browse(cr, uid, pd_ids, context=context):
product_complete.append('['+ str(rec.default_code) + ']'+ ' ' + str(rec.name_template))
print "\n\n bom_ids ", bom_ids
domain = [('id','=',bom_ids)]
return {
'type': 'ir.actions.act_window',
'name': _('BOM'),
'res_model': 'mrp.bom',
'view_mode': 'tree',
'target': 'new',
'domain': domain,
}

最佳答案

bom_ids = []

它是一个列表,意味着会有多个值。您传递的域是

[('id','=',bom_ids)]

所以如果我们举个小例子,那么考虑 bom_ids = [1,2,3];那么域名将是

domain = [('id','=',bom_ids)] -> [('id','=',[1,2,3])]

根据 SQL 概念,这是错误的。 id = 将始终具有单一值。对于多个值,您应该使用 inlike

您可以尝试的解决方案是

domain = [('id','in',bom_ids)]

希望这对您有帮助。

谢谢。

关于python - 错误: dictionary update sequence element #0 has length 3; 2 is required,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27532182/

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