2013-01-13 9 views
34

gerekli ama bu hatayı alıyorum edilir: "dictionary update sequence element #0 has length 3; 2 is required"sözlük güncelleme sırası elemanı # 0, uzunluğu 3; 2 Diğer nesnesi aracılığıyla nesneye <code>account.bank.statement.line</code> için çizgiler eklemek istediğiniz

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 

Bunun üzerine değiştirildi ama sonra bu hata ile karşılaştım:

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 

Kodu: Bu hata yukarı kaldırdı

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

geçerli nesne/sınıf nedir? Doğrudan çizgi oluşturmak mı yoksa mevcut nesnenizde one2many olarak satır eklemek mi istiyorsunuz? Burada sorun, create() 'deki listeyi geçemezsiniz. Sözlüğü geçmelisiniz. –

+0

Cevabınız için teşekkürler, durumdan hemen sonra hesap tablosuna account_bank_statement_line satır eklemek için hr_expense_expense değerini değiştirdim: 'confirm' – rindra

cevap

40

Çünkü yanlış bir sıra (list veya tuple) yapısı kullanarak dict nesnesini güncelleştirmeye çalışıyorsunuz.

cash_id.create(cr, uid, lines,context=None) dict nesnesine lines dönüştürmeye çalışırken:

(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 
      }) 

düzgün dict nesnesine dönüştürmek için bu başlığın ikinci sıfır çıkarın.

o kendini test etmek için, piton kabuğu içine bu deneyin:

>>> 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) 
>>> 
İlgili konular