ValueError:字典更新序列元素#0的长度为1; 2个为必填项 [英] ValueError: dictionary update sequence element #0 has length 1; 2 is required

查看:96
本文介绍了ValueError:字典更新序列元素#0的长度为1; 2个为必填项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为计算字段old_default_code返回5,并且出现以下错误:

I am returning 5 for my computational field old_default_code, and I am getting the following error:

ValueError:字典更新序列元素#0的长度为1;需要2个

ValueError: dictionary update sequence element #0 has length 1; 2 is required

我在做什么错了?

函数的Python代码:

def _old_default_code(self, cr, uid, ids, name, arg, context=None):
        return '5'
_columns = {
            'old_default_code' : fields.function(_old_default_code, type='char', size=32, method=True, store=False, multi=False) }

XML代码:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <!-- mrp_bom -->
        <record id="adamson_mrp_bom_form_view" model="ir.ui.view">
            <field name="name">adamson.mrp.bom.form.view</field>
            <field name="model">mrp.bom</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="mrp.mrp_bom_form_view" />
            <field name="arch" type="xml">

                <xpath expr="//notebook/page[@string='Components']/field/tree[@string='Components']/field[@name='sequence']" position="before" >
                                         <field name="old_default_code" />
                     <button class="oe_inline oe_stat_button" type="object" string="Go!" icon="gtk-go-forward" name="action_go" 
                     attrs="{'invisible':[('old_default_code','=', '5')]}"  />

                               </xpath>

推荐答案

@Nebojsa

field.function总是希望返回字典,在您的情况下,您只是返回整数".系统的默认行为是期望使用字典,其中的键是记录的"id",而值是要返回的值.

The field.function always expect a dictionary to be returned and in your case you are just return an "Integer". The default behaviour of the system is that it expects a dictionary where the key is the "id" of the record and value is the value you want to return.

例如:

如果您要返回"5",且记录ID为2,则字典为{2:5}

If you want to return '5' in your case and the record id is 2 then following will be the dictionary {2:5}

注意:

在进行计算时,对于所有这些id,无论您在方法中获得的id是什么,您都应在字典中返回一个值,即使找不到/计算没有值,也应针对这些id至少返回false,但请确保您至少要针对函数中获得的所有ID返回一些值.

While doing calculation whatever ids you have got in your method for all those ids you should return a value in the dictionary, even if no value can be found/calculated then you should return at least false against those ids, but make sure you at least return some value against all the ids that you have got in your function.

如果您在此方面遇到麻烦,请告诉我

Let me know if you find trouble in this

希望这会有所帮助.

这篇关于ValueError:字典更新序列元素#0的长度为1; 2个为必填项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆