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

42
jr_einvoice/mustang.py Normal file
View File

@@ -0,0 +1,42 @@
from __future__ import annotations
from pathlib import Path
import subprocess
class MustangError(RuntimeError):
pass
def _run(jar: Path, args: list[str], logger) -> subprocess.CompletedProcess[str]:
if not jar.exists():
raise MustangError(f"Mustang jar not found: {jar}")
cmd = ["java", "-Xmx1G", "-Dfile.encoding=UTF-8", "-jar", str(jar)] + args
logger.debug("Running Mustang: %s", " ".join(cmd))
proc = subprocess.run(cmd, capture_output=True, text=True)
logger.debug("Mustang stdout:\n%s", proc.stdout.strip())
logger.debug("Mustang stderr:\n%s", proc.stderr.strip())
return proc
def combine_facturx(jar: Path, source_pdf: Path, source_xml: Path, out_pdf: Path, logger, profile: str = "E") -> Path:
out_pdf.parent.mkdir(parents=True, exist_ok=True)
proc = _run(jar, [
"--action", "combine",
"--source", str(source_pdf),
"--source-xml", str(source_xml),
"--out", str(out_pdf),
"--profile", profile
], logger)
if proc.returncode != 0:
raise MustangError(f"Mustang combine failed (rc={proc.returncode}). See logs for details.")
return out_pdf
def validate(jar: Path, source: Path, out_report: Path, logger, no_notices: bool = True) -> Path:
out_report.parent.mkdir(parents=True, exist_ok=True)
args = []
if no_notices:
args += ["--no-notices"]
args += ["--action", "validate", "--source", str(source)]
proc = _run(jar, args, logger)
if proc.returncode != 0:
raise MustangError(f"Mustang validate failed (rc={proc.returncode}). See logs for details.")
content = proc.stdout.strip() or "<report>empty stdout from Mustang; check logs</report>"
out_report.write_text(content, encoding="utf-8")
return out_report