TypeError: appliquer() takes at least 4 arguments (2 given)

TypeError: appliquer() takes at least 4 arguments (2 given)

这是我的功能:

@api.multi
def appliquer(self,cr,ids,uid, context= None):
    wizard = self.browse(cr, uid, ids[0], context)
    res=[]        
    for x in wizard:
        if x.vendeur:
            res.append(('user_id','=',x.vendeur.id))
        if x.agence_id:
            res.append(x.agence_id)        
        if x.open:
            res.append(x.ca)
        if x.draft:
            res.append(x.ca)
        if x.paid:
            res.append(x.ca)
        if x.dare_from and x.date_to:
            res.append(('date_from', '>=', x.date_from.id))
            res.append(('date_to', '<=', x.date_to.id)) 
    return {
        'name' : 'Chiffre d\'affaire',
        'view_type' : 'form',
        'view_mode' : 'tree,graph',
        'res_model' : 'ca.report',
        'type' : 'ir.actions.act.window',
        'target' : 'new',
        'res' : res,
    }

     }

此功能用于显示我的向导中的一些树视图,但是当我单击底部以启动向导时出现此错误:

TypeError: appliquer() takes at least 4 arguments (2 given)

我尝试了很多解决方案,但其中 none 个都有效。

您在这里将新 API 与旧 API 混在一起。您已经用 api.multi 修饰了 appliquer()。这个装饰器让处理新旧 API 样式方法的包装器将方法包装为新样式 API 方法。

通过在按钮上调用此方法,Odoo 会用 2 个参数填充参数,但您的方法需要 4 个参数。

因此您需要将参数更改为 self(新的 API 中不需要更多的按钮方法)并且当然将其重写为使用 self(不需要浏览,并且等等......)或者你只是删除装饰器。

编辑:因为我不再喜欢旧的 API,而且现在它已被弃用,我会将您的方法迁移到新的 API 样式:

@api.multi
def appliquer(self):
    res = []
    for wizard in self:
        if wizard.vendeur:
            res.append(('user_id','=',wizard.vendeur.id))
        if wizard.agence_id:
            res.append(wizard.agence_id)        
        if wizard.open or wizard.draft or wizard.paid:
            res.append(wizard.ca)
        if wizard.dare_from and wizard.date_to:
            res.append(('date_from', '>=', wizard.date_from.id))
            res.append(('date_to', '<=', wizard.date_to.id)) 
    return {
        'name' : 'Chiffre d\'affaire',
        'view_type' : 'form',
        'view_mode' : 'tree,graph',
        'res_model' : 'ca.report',
        'type' : 'ir.actions.act.window',
        'target' : 'new',
        'res' : res,
    }