Ensure booking sheet template/output are UTF-8

This commit is contained in:
OpenClaw Assistant
2026-02-21 20:20:19 +00:00
parent cf0644f4fe
commit a3971dd3e0
2 changed files with 117 additions and 1 deletions

View File

@@ -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", ""))