Skip to content

Commit c197fa6

Browse files
committed
fix: handle invalid xml data
Resolves #12
1 parent b28ff20 commit c197fa6

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

eu_einvoice/european_e_invoice/doctype/e_invoice_import/e_invoice_import.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from frappe import _, _dict, get_site_path
1414
from frappe.model.document import Document
1515
from frappe.model.mapper import get_mapped_doc
16+
from lxml.etree import XMLSyntaxError
1617

1718
from eu_einvoice.schematron import Stylesheet, get_validation_errors
1819
from eu_einvoice.utils import format_heading
@@ -127,7 +128,10 @@ def get_xml_bytes(self) -> bytes:
127128

128129
def read_values_from_einvoice(self) -> None:
129130
xml_bytes = self.get_xml_bytes()
130-
doc = DrafthorseDocument.parse(xml_bytes)
131+
try:
132+
doc = DrafthorseDocument.parse(xml_bytes)
133+
except XMLSyntaxError:
134+
frappe.throw(_("The uploaded file does not contain valid XML data."))
131135

132136
self._validate_schematron(xml_bytes)
133137

@@ -311,7 +315,11 @@ def guess_item_code(self):
311315
continue
312316

313317
if row.seller_product_id and self.supplier:
314-
row.item = frappe.db.get_value("Item Supplier", {"supplier": self.supplier, "supplier_part_no": row.seller_product_id}, "parent")
318+
row.item = frappe.db.get_value(
319+
"Item Supplier",
320+
{"supplier": self.supplier, "supplier_part_no": row.seller_product_id},
321+
"parent",
322+
)
315323

316324
def add_seller_product_ids_to_items(self):
317325
for row in self.items:

0 commit comments

Comments
 (0)