diff --git a/NEWS.rst b/NEWS.rst index 09606471624153b667775d5601c13dc9051281d2_TkVXUy5yc3Q=..d900f10215934baea7e2bebfa647086a6c763e58_TkVXUy5yc3Q= 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -13,6 +13,8 @@ ``import_jsonrpc``: Add ``--allow-import-errors`` & ``--allow-missing-refs`` to log warnings without blocking errors. +``import_jsonrpc``: More lenient float parsing - handle commas / dots / nbspaces. + 13.3.0 ------ diff --git a/odoo_scripts/import_jsonrpc.py b/odoo_scripts/import_jsonrpc.py index 09606471624153b667775d5601c13dc9051281d2_b2Rvb19zY3JpcHRzL2ltcG9ydF9qc29ucnBjLnB5..d900f10215934baea7e2bebfa647086a6c763e58_b2Rvb19zY3JpcHRzL2ltcG9ydF9qc29ucnBjLnB5 100644 --- a/odoo_scripts/import_jsonrpc.py +++ b/odoo_scripts/import_jsonrpc.py @@ -104,7 +104,17 @@ return int(value) if value else 0 def _convert_float(value) -> float: - return float(value) if value else 0.0 + """Convert string to float, handle commas / dots / nbspaces. + From <https://stackoverflow.com/a/55004691>. + """ + if not value: + return 0.0 + value = value.replace("\xa0", "") # Remove nbspaces. + if value.rfind(",") > value.rfind("."): + value = value.replace(".", "").replace(",", ".") + else: + value = value.replace(",", "") + return float(value) def _convert_many2one(xmlid: str) -> Union[None, int]: if xmlid: