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