Skip to content

Commit

Permalink
Merge pull request #484 from frePPLe/18.0
Browse files Browse the repository at this point in the history
Syncing from upstream frePPLe/odoo (18.0)
  • Loading branch information
bt-admin authored Oct 18, 2024
2 parents 3ac6e21 + af70795 commit 906b304
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 137 deletions.
18 changes: 15 additions & 3 deletions frepple/controllers/frepplexml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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")
Expand All @@ -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
Expand Down
136 changes: 2 additions & 134 deletions frepple/controllers/outbound.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -3020,61 +2946,3 @@ def export_onhand(self):
quoteattr(key[1]),
)
yield "</buffers>\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="")

0 comments on commit 906b304

Please sign in to comment.