Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions account_statement_import_camt/tests/test_import_bank_statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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 = """\
<?xml version="1.0" encoding="utf-8"?>
<Document
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:iso:std:iso:20022:tech:xsd:camt.053.001.02"
>
<BkToCstmrStmt>
<Stmt>
<Ntry>
<NtryDtls>
<TxDtls>
<RmtInf>
<Ustrd/>
</RmtInf>
</TxDtls>
</NtryDtls>
</Ntry>
</Stmt>
</BkToCstmrStmt>
</Document>
"""
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."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: <Ustrd />).
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

Expand Down
Loading