我收到错误: 输入错误:map()的参数2必须支持迭代 当试图保存。视图正确呈现,所有计算都是我想要的。但是当我点击保存时,我得到了上面提到的错误。我认为问题在于我传递的对象类型。有人可以建议我应该对下面的代码做些什么改变来解决这个问题吗?
以下是我的代码:
class export_rebate(osv.osv):
_name = 'export.rebate'
def _cal_difference(self, cr, uid, ids, field_names, arg=None, context=None):
res = {}
for item in self.browse(cr, uid, ids, context=context):
res[item.id] = item.rebate_amount or 0.0 - item.amount_received or 0.0
return res
def _get_quantity (self, cr, uid, ids, field_names, arg=None, context=None):
res = {}
for line in self.browse(cr,uid,ids,context=context):
qty = 0.0
invoice = line.invoice_id
if invoice and invoice.invoice_line:
for invline in invoice.invoice_line:
qty += invline.quantity
res[line.id] = qty
return res
def onchange_invoice_id(self, cr, uid, ids, invoice_id):
print 'on_change called'
res = {}
if invoice_id:
inv = self.pool.get('account.invoice').browse(cr, uid, invoice_id)
res['date_invoice'] = inv.date_invoice or False
res['form_e_num'] = inv.form_e_num or False
res['form_e_date'] = inv.form_e_date or False
res['invoice_line'] = [x.id for x in inv.invoice_line or []]
return {'value': res}
_columns = {
'invoice_id': fields.many2one('account.invoice', 'Invoice No.'),
'type': fields.char('Type', size=64, readonly=True, select=True),
'state': fields.char('Status', select=True, readonly=True),
'date_invoice': fields.related('invoice_id', 'date_invoice', string='Invoice Date', relation='account.invoice', type='date', readonly=True),
'form_e_num': fields.related('invoice_id', 'form_e_num', string='Form E No.', relation='account.invoice', type='char', readonly=True),
'form_e_date': fields.related('invoice_id', 'form_e_date', string='Form E Date', relation='account.invoice', type='date', readonly=True),
'invoice_line': fields.related('invoice_id', 'id', relation='account.invoice.line', type='one2many', readonly=True),
'quantity': fields.function(_get_quantity, type='float', digits=(16,2), string='Quantity', store=True, readonly=True),
'rebate_file_num': fields.char('Rebate File No.', size=64, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'claim_file_date': fields.date('Claim File Date', select=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'rebate_amount': fields.float('Rebate Amount', digits=(16,2), states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'rebate_rate': fields.float('Rebate Rate', digits=(16,2), states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'gd_num': fields.char('G.D. No.', size=64, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'gd_date': fields.date('G.D. Date', select=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'prc_date': fields.date('PRC Date', select=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'claim_sbmt_date': fields.date('Claim Submission Date', select=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'cheque_num': fields.char('Cheque No.', size=64, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'cheque_date': fields.date('Cheque Date', select=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'amount_received': fields.float('Amount Received', digits=(16,2), states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'Net_amt_rcvd': fields.float('net Amount Received', digits=(16,2), states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}),
'difference': fields.function(_cal_difference, type='float', digits=(16,2), string='Difference', store=True, readonly=True)
}
_default = {
'quantity': 0.00
}
export_rebate()
答案 0 :(得分:0)
我认为问题出在onchange_invoice_id
方法中。
这个似乎很可疑res['invoice_line'] = [x.id for x in inv.invoice_line or []]
。
请注意这一行。