0

我收到错误消息:类型错误: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() 
4

1 回答 1

0

我认为问题出在onchange_invoice_id方法上。

这似乎有点可疑res['invoice_line'] = [x.id for x in inv.invoice_line or []]。在评论此行后尝试。

于 2013-04-19T17:08:38.030 回答