2013-01-13 18 views
34

मैं अन्य वस्तु के माध्यम से वस्तु account.bank.statement.line लिए लाइनों को जोड़ना चाहते हैं, लेकिन मैं इस त्रुटि मिलती है: "dictionary update sequence element #0 has length 3; 2 is required"शब्दकोश अद्यतन अनुक्रम तत्व # 0 लंबाई 3 है; 2 आवश्यक है

def action_account_line_create(self, cr, uid, ids): 
    res = False 
    cash_id = self.pool.get('account.bank.statement.line') 
    for exp in self.browse(cr, uid, ids): 
     company_id = exp.company_id.id 
     #statement_id = exp.statement_id.id 
     lines = [] 
     for l in exp.line_ids: 
      lines.append((0, 0, { 
       'name': l.name, 
       'date': l.date, 
       'amount': l.amount, 
       'type': l.type, 
       'statement_id': exp.statement_id.id, 
       'account_id': l.account_id.id, 
       'account_analytic_id': l.analytic_account_id.id, 
       'ref': l.ref, 
       'note': l.note, 
       'company_id': l.company_id.id 
      })) 

     inv_id = cash_id.create(cr, uid, lines,context=None) 
     res = inv_id 
    return res 

मैं उस पर इसे बदल लेकिन फिर मैं इस त्रुटि का सामना किया:

File "C:\Program Files (x86)\OpenERP 6.1-20121029-003136\Server\server\.\openerp\workflow\wkf_expr.py", line 68, in execute 
    File "C:\Program Files (x86)\OpenERP 6.1-20121029-003136\Server\server\.\openerp\workflow\wkf_expr.py", line 58, in _eval_expr 
    File "C:\Program Files (x86)\OpenERP 6.1-20121029-003136\Server\server\.\openerp\tools\safe_eval.py", line 241, in safe_eval 
    File "C:\Program Files (x86)\OpenERP 6.1-20121029-003136\Server\server\.\openerp\tools\safe_eval.py", line 108, in test_expr 
    File "<string>", line 0 
^
SyntaxError: unexpected EOF while parsing 

कोड:

def action_account_line_create(self, cr, uid, ids, context=None): 
    res = False 
    cash_id = self.pool.get('account.bank.statement.line') 
    for exp in self.browse(cr, uid, ids): 
     company_id = exp.company_id.id 
     lines = [] 
     for l in exp.line_ids: 
      res = cash_id.create (cr, uid, { 
       'name': l.name, 
       'date': l.date, 
       'amount': l.amount, 
       'type': l.type, 
       'statement_id': exp.statement_id.id, 
       'account_id': l.account_id.id, 
       'account_analytic_id': l.analytic_account_id.id, 
       'ref': l.ref, 
       'note': l.note, 
       'company_id': l.company_id.id 
      }, context=None) 
    return res 
+0

अपने वर्तमान वस्तु/वर्ग क्या है? क्या आप सीधे लाइन बनाना चाहते हैं या आप अपनी वर्तमान ऑब्जेक्ट में एक 2many के रूप में लाइन जोड़ना चाहते हैं? यहां समस्या यह है कि आप सूची() में सूची पास नहीं कर सकते हैं। आपको शब्दकोश पास करना होगा। –

+0

आपके उत्तर के लिए धन्यवाद, मैंने hr_expense_expense को तालिका के बाद सीधे table_bank_statement_line पर लाइन जोड़ने के लिए बदल दिया: 'पुष्टि करें' – rindra

उत्तर

40

यह त्रुटि ऊपर उठाया क्योंकि आप गलत अनुक्रम (list या tuple) संरचना का उपयोग कर dict ऑब्जेक्ट को अपडेट करने का प्रयास कर रहे हैं।

cash_id.create(cr, uid, lines,context=None) dict वस्तु में lines कन्वर्ट करने के लिए कोशिश कर रहा है:

(0, 0, { 
       'name': l.name, 
       'date': l.date, 
       'amount': l.amount, 
       'type': l.type, 
       'statement_id': exp.statement_id.id, 
       'account_id': l.account_id.id, 
       'account_analytic_id': l.analytic_account_id.id, 
       'ref': l.ref, 
       'note': l.note, 
       'company_id': l.company_id.id 
      }) 

इस टपल से दूसरे शून्य निकालें ठीक से एक dict वस्तु में परिवर्तित करने के लिए।

यह अपने आप परीक्षण करने के लिए, अजगर खोल में इस प्रयास करें:

>>> l=[(0,0,{'h':88})] 
>>> a={} 
>>> a.update(l) 

Traceback (most recent call last): 
    File "<pyshell#11>", line 1, in <module> 
    a.update(l) 
ValueError: dictionary update sequence element #0 has length 3; 2 is required 
>>> l=[(0,{'h':88})] 
>>> a.update(l) 
>>>