From e534212cf15e61a29de9c52393e501d3071b77e4 Mon Sep 17 00:00:00 2001 From: DiG Date: Mon, 17 Jan 2022 14:39:27 +0100 Subject: [PATCH] WIP lookup commands --- odoo-rpc.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/odoo-rpc.py b/odoo-rpc.py index d1fe4b7..4ca9fac 100755 --- a/odoo-rpc.py +++ b/odoo-rpc.py @@ -9,9 +9,12 @@ import os import sys import json import odoorpc # pip install odoorpc +#from typing import Iterable # > py38 +from collections import Iterable # < py38 from renderers import render, tsv + def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) @@ -50,6 +53,17 @@ eprint( MODEL_IGNORE ) + +def flatten(items): + """Yield items from any nested iterable; see Reference.""" + for x in items: + if isinstance(x, Iterable) and not isinstance(x, (str, bytes)): + for sub_x in flatten(x): + yield sub_x + else: + yield x + + def jlog( obj ): print( json.dumps(obj, indent=4) ) #"\t") ) @@ -338,7 +352,7 @@ def flatten_stack( data ): if type(data[key]) in [list,dict]: flat += flatten_stack(data[key]) - return flat + return list(flatten(flat))