Ensure booking sheet template/output are UTF-8
This commit is contained in:
@@ -34,7 +34,20 @@ def _extract_amount(s: str) -> float:
|
||||
def render_booking_rtf(template_path: Path, output_path: Path, data: dict) -> None:
|
||||
if not template_path.exists():
|
||||
return
|
||||
txt = template_path.read_text(encoding="utf-8", errors="ignore")
|
||||
|
||||
raw = template_path.read_bytes()
|
||||
txt = None
|
||||
for enc in ("utf-8", "cp1251", "utf-8-sig"):
|
||||
try:
|
||||
txt = raw.decode(enc)
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
if txt is None:
|
||||
txt = raw.decode("utf-8", errors="ignore")
|
||||
|
||||
# Явно фиксируем UTF-8 кодировку RTF (для совместимости)
|
||||
txt = txt.replace("\\rtf1\\ansi", "\\rtf1\\ansi\\ansicpg65001", 1)
|
||||
|
||||
total_num = _extract_amount(data.get("total", ""))
|
||||
prepay_num = _extract_amount(data.get("prepay", ""))
|
||||
|
||||
Reference in New Issue
Block a user