Initial version of the E-Invoice solution of JR IT Services

This commit is contained in:
2026-02-16 17:02:03 +01:00
commit e0c15fc7f2
36 changed files with 1407 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
from __future__ import annotations
from pathlib import Path
import re
from datetime import date
DEFAULT_PATTERN = r"(?P<year>\d{4})-(?P<seq>\d{4})"
def suggest_next_invoice_number(invoices_root: Path, year: int | None = None, pattern: str = DEFAULT_PATTERN) -> str:
invoices_root = invoices_root.expanduser().resolve()
y = year or date.today().year
rx = re.compile(pattern)
max_seq = 0
if invoices_root.exists():
for d in invoices_root.iterdir():
if not d.is_dir():
continue
m = rx.search(d.name)
if not m:
continue
try:
yr = int(m.group("year"))
seq = int(m.group("seq"))
except Exception:
continue
if yr == y and seq > max_seq:
max_seq = seq
return f"{y}-{max_seq+1:04d}"