当我想执行我的copy_data,获取对象值并递增它,并复制对象时我得到这个错误:TypeError:类型' int'的参数是不可迭代的
class immo_assurance(osv.osv):
_name = "immo.assurance"
_description = "Assurance"
def copy_data(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
res = 1
idea = self.browse(cr, uid, id)
res += int(idea.nContrat)
#res = default.get('nContrat')
default['nContrat'] = res
return super(immo_assurance, self).copy_data(
cr, uid, id, default=res, context=context)
_columns = {
'name':fields.char('Code',size=10,required=True),
'nContrat':fields.integer('Ndu contrat',size=60,required=True),
'dDebut':fields.date('Début'),
'dFin':fields.date('Fin'),
'id_societe' : fields.many2one('immo.societe' ,'Société',required=True),
'cAnnuel':fields.float('Cout annuel',size=60),
'commentaire':fields.char('Commentaires',size=10),
'articles':fields.one2many('immo.article','assurance','Liste Articles', readonly=True),
}
immo_assurance()
`
答案 0 :(得分:0)
默认是一个你无法返回的词典:
super(immo_assurance, self).copy_data(cr, uid, id, **default=res**, context=context)`
默认= res * 这是不正确的
但
def copy_data(self, cr, uid, id, default=None, context=None):
if default is None:
default = {}
res = 1
idea = self.browse(cr, uid, id)
res += int(idea.nContrat)
default['nContrat'] = res
return super(immo_assurance, self).copy_data(
cr, uid, id, default, context)