Skip to content

Commit b40013c

Browse files
committed
fix: use local safe filename helper for xml attachment naming
Frappe v15 does not expose get_safe_file_name on file utils; mirror the v17+ implementation beside get_xml_attachment_file_base_name as _get_safe_file_name.
1 parent 4884d36 commit b40013c

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

eu_einvoice/european_e_invoice/custom/sales_invoice.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from drafthorse.models.trade import LogisticsServiceCharge
1616
from drafthorse.models.tradelines import LineItem
1717
from frappe import _
18-
from frappe.core.doctype.file.utils import find_file_by_url, get_safe_file_name
18+
from frappe.core.doctype.file.utils import find_file_by_url
1919
from frappe.core.utils import html2text
2020
from frappe.model.naming import parse_naming_series
2121
from frappe.utils import cstr
@@ -1141,7 +1141,7 @@ def get_xml_attachment_file_base_name(doc, *, pattern: str | None = None) -> str
11411141
11421142
Uses *pattern* when given, otherwise reads *Auto name format for XML file*
11431143
from **E Invoice Settings**. Falls back to `doc.name` when the pattern is
1144-
empty or fails to resolve. Result is sanitized via `get_safe_file_name`
1144+
empty or fails to resolve. Result is sanitized via `_get_safe_file_name`
11451145
(same rules as **File** attachments).
11461146
"""
11471147
if pattern is None:
@@ -1159,8 +1159,13 @@ def get_xml_attachment_file_base_name(doc, *, pattern: str | None = None) -> str
11591159
)
11601160
base = ""
11611161
if base:
1162-
return get_safe_file_name(base)
1163-
return get_safe_file_name(doc.name)
1162+
return _get_safe_file_name(base)
1163+
return _get_safe_file_name(doc.name)
1164+
1165+
1166+
def _get_safe_file_name(file_name: str) -> str:
1167+
"""Local-only; mirrors ``get_safe_file_name`` in Frappe v17+ file utils."""
1168+
return re.sub(r"[/\\%?#]", "_", file_name)
11641169

11651170

11661171
def _no_series_counter(_key: str, _digits: int) -> str:

0 commit comments

Comments
 (0)