我正在为计算字段返回5
,得到以下错误:
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>
@内博伊萨
field.function总是希望返回一个字典,在您的情况下,您只是返回一个“整数”。系统的默认行为是它需要一个字典,其中键是记录的“id”,值是要返回的值。
例如:
如果您想返回'5',而记录id是2,那么下面将是字典{2:5}
注:
在计算所有这些id的方法中得到的任何id时,应该在字典中返回一个值,即使找不到/计算不到任何值,也应该至少对这些id返回false,但确保至少对函数中得到的所有id返回一些值。
如果你在这件事上发现麻烦就告诉我
希望这有帮助。。
遇到此错误的最常见方法是当您有类型转换错误时,例如
MWE重新生成错误-
运行此命令会产生错误
ValueError: dictionary update sequence element #0 has length 1; 2 is required
希望这有帮助。
相关问题 更多 >
编程相关推荐