From af70795cac57f6a25b00d4be441ea218cd546170 Mon Sep 17 00:00:00 2001 From: Johan De Taeye Date: Thu, 17 Oct 2024 17:04:12 +0200 Subject: [PATCH] adjusting for odoo 18 changes --- frepple/controllers/frepplexml.py | 18 +++- frepple/controllers/outbound.py | 136 +----------------------------- 2 files changed, 17 insertions(+), 137 deletions(-) diff --git a/frepple/controllers/frepplexml.py b/frepple/controllers/frepplexml.py index 48b52e7..629bf2d 100644 --- a/frepple/controllers/frepplexml.py +++ b/frepple/controllers/frepplexml.py @@ -112,7 +112,14 @@ def authenticate(self, req, database, language, company, version): self.user, password = auth.split(":", 1) if not database or not self.user or not password: raise Exception("Missing user, password or database") - uid = req.session.authenticate(database, self.user, password) + uid = req.session.authenticate( + database, + { + "login": self.user, + "password": password, + "type": "password", + }, + ) if not uid: raise Exception("Odoo basic authentication failed") elif authmeth.lower() == "bearer" and version and version[0] >= 7: @@ -129,7 +136,12 @@ def authenticate(self, req, database, language, company, version): "Missing user, password, company or database in token" ) uid = req.session.authenticate( - database, decoded["user"], decoded["password"] + database, + { + "login": decoded["user"], + "password": decoded["password"], + "type": "password", + }, ) if not uid: raise Exception("Odoo token authentication failed") @@ -140,7 +152,7 @@ def authenticate(self, req, database, language, company, version): if language: # If not set we use the default language of the user req.session.context["lang"] = language - return uid + return uid["uid"] @odoo.http.route( "/frepple/xml", type="http", auth="none", methods=["POST", "GET"], csrf=False diff --git a/frepple/controllers/outbound.py b/frepple/controllers/outbound.py index 3acc490..41fc973 100644 --- a/frepple/controllers/outbound.py +++ b/frepple/controllers/outbound.py @@ -74,79 +74,6 @@ def getData(self, model, search=[], order=None, fields=[], ids=None, object=Fals return self.env[model].search(search).read(fields) -class XMLRPC_generator: - pagesize = 5000 - - def __init__(self, url, db, username, password): - self.db = db - self.password = password - self.env = xmlrpc.client.ServerProxy( - "{}/xmlrpc/2/common".format(url), - context=ssl._create_unverified_context(), - ) - self.uid = self.env.authenticate(db, username, password, {}) - self.env = xmlrpc.client.ServerProxy( - "{}/xmlrpc/2/object".format(url), - context=ssl._create_unverified_context(), - use_builtin_types=True, - headers={"Connection": "keep-alive"}.items(), - ) - self.context = {} - - def setContext(self, **kwargs): - self.context.update(kwargs) - - def callMethod(self, model, id, method, args): - return self.env.execute_kw( - self.db, self.uid, self.password, model, method, [id], [] - ) - - def getData(self, model, search=None, order="id asc", fields=[], ids=[]): - if ids: - page_ids = [ids] - else: - page_ids = [] - offset = 0 - msg = { - "limit": self.pagesize, - "offset": offset, - "context": self.context, - "order": order, - } - while True: - extra_ids = self.env.execute_kw( - self.db, - self.uid, - self.password, - model, - "search", - [search] if search else [[]], - msg, - ) - if not extra_ids: - break - page_ids.append(extra_ids) - offset += self.pagesize - msg["offset"] = offset - if page_ids and page_ids != [[]]: - data = [] - for page in page_ids: - data.extend( - self.env.execute_kw( - self.db, - self.uid, - self.password, - model, - "read", - [page], - {"fields": fields, "context": self.context}, - ) - ) - return data - else: - return [] - - class exporter(object): def __init__( self, @@ -1075,7 +1002,7 @@ def export_items(self): self.route_mto = k for i in self.generator.getData( "product.template", - search=[("type", "not in", ("service", "consu"))], + search=[("type", "not in", ("service", "combo"))], fields=[ "sale_ok", "purchase_ok", @@ -1116,7 +1043,7 @@ def export_items(self): product_template.name->>'en_US') having count(*) > 1 ) t - """, + """, (self.language, self.language), ) for i in self.generator.env.cr.fetchall(): @@ -2980,7 +2907,6 @@ def export_onhand(self): "INNER JOIN stock_location ON stock_quant.location_id = stock_location.id " "WHERE quantity > 0 " "AND stock_location.scrap_location is distinct from true " - "AND stock_location.return_location is distinct from true " "AND stock_location.usage = 'internal' " "GROUP BY product_id, stock_quant.location_id " "ORDER BY stock_quant.location_id ASC" @@ -3020,61 +2946,3 @@ def export_onhand(self): quoteattr(key[1]), ) yield "\n" - - -if __name__ == "__main__": - # - # When calling this script directly as a Python file, the connector uses XMLRPC - # to connect to odoo and download all data. - # - # This is useful for debugging connector updates remotely, when you don't have - # direct access to the odoo server itself. - # This mode of working is not recommended for production use because of performance - # considerations. - # - # DEPRECATED EXPERIMENTAL FEATURE!!! - # This feature was always experimental, and we now see it as a dead end. - # - import argparse - from warnings import warn - - warn("The XMLRPC odoo connector is deprecated", DeprecationWarning) - - parser = argparse.ArgumentParser(description="Debug frepple odoo connector") - parser.add_argument( - "--url", help="URL of the odoo server", default="http://localhost:8069" - ) - parser.add_argument("--db", help="Odoo database to connect to", default="odoo14") - parser.add_argument( - "--username", help="User name for the odoo connection", default="admin" - ) - parser.add_argument( - "--password", help="User password for the odoo connection", default="admin" - ) - parser.add_argument( - "--company", help="Odoo company to use", default="My Company (Chicago)" - ) - parser.add_argument( - "--timezone", help="Time zone to convert odoo datetime fields to", default="UTC" - ) - parser.add_argument( - "--singlecompany", - default=False, - help="Limit the data to a single company only.", - action="store_true", - ) - args = parser.parse_args() - - generator = XMLRPC_generator(args.url, args.db, args.username, args.password) - xp = exporter( - generator, - None, - uid=generator.uid, - database=generator.db, - company=args.company, - mode=1, - timezone=args.timezone, - singlecompany=True, - ) - for i in xp.run(): - print(i, end="")