Search code examples
pythonapiodooodoo-11

How to fix 'TypeError: unlink() missing 1 required positional argument: \'values\'\n''


Im using Python 3.6 and xmlrpc to unlink all canceled Sale orders in odoo 11 CE but im still getting this error:

odoo11/odoo/api.py", line 690, in call_kw_multi\n    result = method(recs, args, *kwargs)\nTypeError: unlink() missing 1 required positional argument: \'values\'\n'>

ive also tried somehting like:

            , [[sale_id]])

instead of:

            , [sale_id])

heres my code:

import xmlrpc.client

class Odoo():
    def __init__(self):
        self.DATA = "DB"
        self.USER = "USER"
        self.PASS = "PASS"
        self.PORT = "8069"
        self.URL = "http://localhost"
        self.URL_COMMON = "{}:{}/xmlrpc/2/common".format(
            self.URL, self.PORT)
        self.URL_OBJECT = "{}:{}/xmlrpc/2/object".format(
            self.URL, self.PORT)
    def authenticateOdoo(self):
        self.ODOO_COMMON = xmlrpc.client.ServerProxy(self.URL_COMMON)
        self.ODOO_OBJECT = xmlrpc.client.ServerProxy(self.URL_OBJECT)
        self.UID = self.ODOO_COMMON.authenticate(
            self.DATA
            , self.USER
            , self.PASS
            , {})
def main():
    od = Odoo()
    od.authenticateOdoo()
    sale_ids = od.ODOO_OBJECT.execute_kw(od.DATA, od.UID, od.PASS, 'sale.order', 'search', [[("state", "=", "cancel")]])
    od.ODOO_OBJECT.execute_kw(od.DATA, od.UID, od.PASS, 'sale.order', 'unlink', [sale_ids])
    print(od.UID)

if __name__ == '__main__':
    main()

Solution

  • This error is python error, you called a method that is defined with positional argument values without argument. The problem here the unlink method of a Model don't accept any arguement.

    So check your costum addons where did you inherit the sale.order model and you override the unlink method and remove values argument.

    Look for this method in your odoo instance and remove values arguement restart the server and everything will be fine.

       _inherit = 'sale.order'
    
      ......
      ......
    
       @api.multi
       def unlink(values):