错误:字典更新序列元素#0的长度为3;2是必需的

时间:2022-10-10 02:27:55

When the onchange...() function is executed I am getting the error:

当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

Here is my code. I think error has something to do with domain:

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

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

1 个解决方案

#1


3  

bom_ids = []

bom_ids =[]

It is a list, means more then one value will be there.And the domain that you are passing is

它是一个列表,意味着一个值会有更多。你要传递的定义域是

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

[(“id”、“=”,bom_ids))

so if we take small example then consider that bom_ids = [1,2,3]; then the domain will be

如果我们举个小例子,然后考虑bom_ids = [1,2,3];那么定义域就是

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

域=[(“id”、“=”,bom_ids)]- >[(“id”、“=”,[1,2,3]))

Which is wrong as per SQL concept. the id = will always have single value. for multiple values you should use either in or like.

根据SQL概念,这是错误的。id =总是只有一个值。对于多个值,您应该使用in或like。

Here the solution you can try is

这里你可以尝试的解决方法是

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

域=[(“id”,“在”,bom_ids))

Hope this will help you.

希望这对你有帮助。

Thanks.

谢谢。

#1


3  

bom_ids = []

bom_ids =[]

It is a list, means more then one value will be there.And the domain that you are passing is

它是一个列表,意味着一个值会有更多。你要传递的定义域是

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

[(“id”、“=”,bom_ids))

so if we take small example then consider that bom_ids = [1,2,3]; then the domain will be

如果我们举个小例子,然后考虑bom_ids = [1,2,3];那么定义域就是

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

域=[(“id”、“=”,bom_ids)]- >[(“id”、“=”,[1,2,3]))

Which is wrong as per SQL concept. the id = will always have single value. for multiple values you should use either in or like.

根据SQL概念,这是错误的。id =总是只有一个值。对于多个值,您应该使用in或like。

Here the solution you can try is

这里你可以尝试的解决方法是

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

域=[(“id”,“在”,bom_ids))

Hope this will help you.

希望这对你有帮助。

Thanks.

谢谢。