2014-01-29 83 views
0

创建 'LINE_NO' 当我更新的价值,它抛出了KeyError异常列:40field.function - KeyError异常:40

我的代码:

def _get_line_no(self, cr, uid, ids, line_no, arg, context=None): 
    res = {} 
    for record in self.browse(cr, uid, ids, context=context):      
     nextno =0 
     no = record.next_line_no   
     next_no = nextno + no 
     total =+ next_no 
     res={ 
        'next_line_no':next_no, 
        'line_no': total 
     } 
    return res 

_columns = { 
'line_no':fields.function(_get_line_no,string='Line No',type='integer'), 
'next_line_no':fields.integer(' Next Line No'), 
    } 
_defaults = { 
    'next_line_no':1 
    } 

抛出错误:KeyError异常:40

我该如何解决?

回答

2

next_line_no是一个数据库字段,所以它不会影响动态的方式。

您需要修改这种方式,

def _get_line_no(self, cr, uid, ids, line_no, arg, context=None): 
    res = {} 
    for record in self.browse(cr, uid, ids, context=context):      
     nextno =0 
     no = record.next_line_no   
     next_no = nextno + no 
     total += next_no 
     res[record.id]={ 
        'next_line_no':next_no, 
        'line_no': total 
     } 
    return res 

_columns = { 
'line_no':fields.function(_get_line_no,string='Line No',type='integer', multi="lineno"), 
'next_line_no': function(_get_line_no,string='Next Line No',type='integer', multi="lineno", store=True), 
    } 
_defaults = { 
    'next_line_no':1 
    } 

我希望这将喊叫你。

+0

它的工作原理,更正代码总数+ = next_no – 3156938

+0

@dhana真棒! :) –

+0

@AtulArvind谢谢请给+1,所以它是有用的所有用户 – dhana

1

变化由列,

_columns = { 
    'line_no':fields.function(_get_line_no,string='Line No',type='integer', multi="line"), 
    'next_line_no':fields.function(_get_line_no, type='integer', string='next line number' ,multi="line"), 
} 

和你的方法一样,

def _get_line_no(self, cr, uid, ids, field_names, args, context=None): 
    res = {} 
    for record in self.browse(cr, uid, ids, context=context):      
     nextno =0 
     no = record.next_line_no   
     next_no = nextno + no 
     total += next_no 
     res[record.id]={ 
        'next_line_no':next_no, 
        'line_no': total 
     } 
    return res 

这将工作。

+0

它没有进入for循环抛出错误:AttributeError:'模块'对象没有属性'tracebacklimit' – 3156938

+0

哦!我错了+“总+ = next_no” –