17 lines
514 B
Python
17 lines
514 B
Python
from __future__ import annotations
|
|
import re
|
|
|
|
def slugify(value: str, max_len: int = 40) -> str:
|
|
v = value.strip()
|
|
v = re.sub(r"\s+", "_", v)
|
|
v = re.sub(r"[^A-Za-z0-9_\-]+", "", v)
|
|
v = v.strip("_-")
|
|
if len(v) > max_len:
|
|
v = v[:max_len].rstrip("_-")
|
|
return v or "Kunde"
|
|
|
|
def default_invoice_folder_name(invoice_number: str, customer: str | None = None) -> str:
|
|
cust = slugify(customer or "Kunde")
|
|
inv = slugify(invoice_number, max_len=32)
|
|
return f"Rechnung_{inv}_{cust}"
|