Search code examples
pythonodooodoo-8

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


This my function :

@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,
    }

     }

This function is to display some tree views from my wizard, but when I click on the bottom to launch the wizard I get this error :

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

I've tried so many solutions, but none of them are working.


Solution

  • You're mixing the new API with the old API here. You've decorated appliquer() with api.multi. This decorator let's the wrapper, which is handling old and new API style methods, wrap the method as new style API Method.

    By calling this method on a button, Odoo fills up the parameters with 2 arguments, but your method takes 4 instead.

    So you need to either change the arguments to just self (more is not needed in the new API for button methods) and ofcourse rewrite it to using self (no browse needed, and so on...) OR you just remove the decorator.

    Edit: because i don't like the old API anymore, and because it is deprecated nowadays i'll migrate your method to the new API style:

    @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,
        }