From 5e763e3d316a418a10cb3afc926e066518265553 Mon Sep 17 00:00:00 2001 From: Ronald Portier Date: Thu, 30 Apr 2026 11:51:21 +0200 Subject: [PATCH] [FIX] ..import_camt: fix error when node is an empty element Import would have an exception when encountering '': File "/home/odooedprd19/odoo/auto/addons/account_statement_import_camt/wizard/account_statement_import_camt_parser.py", line 60, in parse_transaction_details self.add_value_from_node( ~~~~~~~~~~~~~~~~~~~~~~~~^ ns, ^^^ ...<8 lines>... join_str="\n", ^^^^^^^^^^^^^^ ) ^ File "/home/odooedprd19/odoo/auto/addons/account_statement_import_camt/wizard/account_statement_import_camt_parser.py", line 53, in add_value_from_node attr_value = join_str.join([x.text for x in found_node]) TypeError: sequence item 0: expected str instance, NoneType found --- .../tests/test_import_bank_statement.py | 44 +++++++++++++++++++ .../account_statement_import_camt_parser.py | 5 ++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/account_statement_import_camt/tests/test_import_bank_statement.py b/account_statement_import_camt/tests/test_import_bank_statement.py index 0b9aeab8d..0dbc80f9d 100644 --- a/account_statement_import_camt/tests/test_import_bank_statement.py +++ b/account_statement_import_camt/tests/test_import_bank_statement.py @@ -9,6 +9,8 @@ from datetime import date from pathlib import Path +from lxml import etree + from odoo.tests.common import TransactionCase from odoo.tools.misc import file_path @@ -95,6 +97,48 @@ def test_parse_txdtls(self): def test_parse_no_ntry(self): self._do_parse_test("test-camt053-no-ntry", "golden-camt053-no-ntry.pydata") + def test_parse_empty_element(self): + DATA = """\ + + + + + + + + + + + + + + + + + """ + root = etree.fromstring(DATA, parser=etree.XMLParser(recover=True)) + ns = root.tag[1 : root.tag.index("}")] + transaction = {} + details_nodes = root.xpath("//ns:NtryDtls/ns:TxDtls", namespaces={"ns": ns}) + node = details_nodes[0] + self.parser.add_value_from_node( + ns, + node, + [ + "./ns:RmtInf/ns:Ustrd|./ns:RtrInf/ns:AddtlInf", + "./ns:AddtlNtryInf", + "./ns:Refs/ns:InstrId", + ], + transaction, + "payment_ref", + join_str="\n", + ) + self.assertNotIn("payment_ref", transaction) + class TestImport(TransactionCase): """Run test to import camt import.""" diff --git a/account_statement_import_camt/wizard/account_statement_import_camt_parser.py b/account_statement_import_camt/wizard/account_statement_import_camt_parser.py index 2b7b7229d..6c3ac9f79 100644 --- a/account_statement_import_camt/wizard/account_statement_import_camt_parser.py +++ b/account_statement_import_camt/wizard/account_statement_import_camt_parser.py @@ -50,7 +50,10 @@ def add_value_from_node(self, ns, node, xpath_str, obj, attr_name, join_str=None elif join_str is None: attr_value = found_node[0].text else: - attr_value = join_str.join([x.text for x in found_node]) + # x.text can be None for empty element (example: ). + attr_value = join_str.join([x.text for x in found_node if x.text]) + if not attr_value: + continue obj[attr_name] = attr_value break