2013-01-13 29 views
34

Tôi muốn thêm dòng để các đối tượng account.bank.statement.line thông qua đối tượng khác nhưng tôi nhận được lỗi này: "dictionary update sequence element #0 has length 3; 2 is required"phần tử cập nhật từ điển # 0 có độ dài 3; 2 là cần thiết

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 

tôi đã thay đổi nó trên đó, nhưng sau đó tôi chạy vào lỗi này:

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 

Code:

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

đối tượng hiện tại/lớp học của bạn là gì? Bạn có muốn tạo dòng trực tiếp hoặc bạn muốn thêm dòng như một2many trong đối tượng hiện tại của bạn? Vấn đề ở đây là bạn không thể chuyển danh sách trong create(). Bạn phải chuyển từ điển. –

+0

cảm ơn câu trả lời của bạn, tôi đã thay đổi hr_expense_expense để thêm dòng trực tiếp vào bảng account_bank_statement_line sau trạng thái: 'confirm' – rindra

Trả lời

40

lỗi này dấy lên vì bạn đang cố gắng cập nhật đối tượng dict bằng cách sử dụng cấu trúc chuỗi sai (list hoặc tuple).

cash_id.create(cr, uid, lines,context=None) cố gắng để chuyển đổi lines vào đối tượng dict:

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

Tháo thứ hai không từ tuple này để chuyển đổi đúng cách nó thành một đối tượng dict.

Để kiểm tra nó tự của bạn, hãy thử này vào vỏ python:

>>> 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) 
>>> 
Các vấn đề liên quan