diff --git a/NEWS.rst b/NEWS.rst index 591715545a0cd8c8e768e2c9a9be7bfff433f4a0_TkVXUy5yc3Q=..27db41a41e3f84d21fd5fdbb51b42b16a6332563_TkVXUy5yc3Q= 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -11,6 +11,8 @@ ``docker_build`` also tag with any current tag if any. +``import_jsonrpc``: Add ``--allow-missing-refs`` to log warnings on missing XMLIDs instead of stopping with a blocking error. + 13.3.0 ------ diff --git a/odoo_scripts/import_jsonrpc.py b/odoo_scripts/import_jsonrpc.py index 591715545a0cd8c8e768e2c9a9be7bfff433f4a0_b2Rvb19zY3JpcHRzL2ltcG9ydF9qc29ucnBjLnB5..27db41a41e3f84d21fd5fdbb51b42b16a6332563_b2Rvb19zY3JpcHRzL2ltcG9ydF9qc29ucnBjLnB5 100644 --- a/odoo_scripts/import_jsonrpc.py +++ b/odoo_scripts/import_jsonrpc.py @@ -20,5 +20,5 @@ _logger = logging.getLogger(__name__) -__version__ = "1.0.2" +__version__ = "1.1.0" __date__ = "2020-02-17" @@ -24,5 +24,5 @@ __date__ = "2020-02-17" -__updated__ = "2020-09-11" +__updated__ = "2021-12-29" def import_with_jsonrpc( @@ -36,6 +36,7 @@ model_filenames: List[Dict[str, str]], delimiter: str = ",", extra_context: Dict[str, str] = dict(), + allow_missing_refs: bool = False, ) -> int: o, session_id = odoo_login( database, host, login, password, port, protocol, timeout @@ -51,6 +52,6 @@ xmlid_cache: Dict[str, int] = dict() - def _ref(xmlid: str, raise_if_not_found: bool = True) -> int: + def _ref(xmlid: str, raise_if_not_found: bool = True) -> Union[bool, int]: if xmlid not in xmlid_cache: full_xmlid = xmlid if "." in xmlid else "." + xmlid @@ -55,8 +56,14 @@ if xmlid not in xmlid_cache: full_xmlid = xmlid if "." in xmlid else "." + xmlid - xmlid_cache[xmlid] = imd.xmlid_to_res_id( - full_xmlid, raise_if_not_found - ) + try: + record_id = imd.xmlid_to_res_id(full_xmlid, raise_if_not_found) + except RPCError as error: + if allow_missing_refs: + _logger.warning(str(error)) + record_id = False + else: + raise + xmlid_cache[xmlid] = record_id return xmlid_cache[xmlid] def _get_imf(model: str, field_name: str): @@ -310,6 +317,14 @@ parser.add_argument( "--context", help="Extra context (key=value)", action="append" ) + parser.add_argument( + "--allow-missing-refs", + help=( + "Log warnings on missing XMLIDs instead of stopping with a " + "blocking error." + ), + action="store_true", + ) nmspc = parser.parse_args(argv) apply(nmspc) @@ -333,6 +348,7 @@ ), delimiter=nmspc.delimiter, extra_context=extra_context, + allow_missing_refs=nmspc.allow_missing_refs, )