Skip to content

Commit

Permalink
fix: handle invalid xml data
Browse files Browse the repository at this point in the history
Resolves #12
  • Loading branch information
barredterra committed Dec 10, 2024
1 parent b28ff20 commit c197fa6
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from frappe import _, _dict, get_site_path
from frappe.model.document import Document
from frappe.model.mapper import get_mapped_doc
from lxml.etree import XMLSyntaxError

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

def read_values_from_einvoice(self) -> None:
xml_bytes = self.get_xml_bytes()
doc = DrafthorseDocument.parse(xml_bytes)
try:
doc = DrafthorseDocument.parse(xml_bytes)
except XMLSyntaxError:
frappe.throw(_("The uploaded file does not contain valid XML data."))

self._validate_schematron(xml_bytes)

Expand Down Expand Up @@ -311,7 +315,11 @@ def guess_item_code(self):
continue

if row.seller_product_id and self.supplier:
row.item = frappe.db.get_value("Item Supplier", {"supplier": self.supplier, "supplier_part_no": row.seller_product_id}, "parent")
row.item = frappe.db.get_value(
"Item Supplier",
{"supplier": self.supplier, "supplier_part_no": row.seller_product_id},
"parent",
)

def add_seller_product_ids_to_items(self):
for row in self.items:
Expand Down

0 comments on commit c197fa6

Please sign in to comment.