2014-01-29 134 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」 –