quints 0.19.0__tar.gz → 0.20.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. {quints-0.19.0 → quints-0.20.0}/PKG-INFO +2 -1
  2. {quints-0.19.0 → quints-0.20.0}/pyproject.toml +2 -1
  3. {quints-0.19.0 → quints-0.20.0}/src/quints/cli.py +6 -2
  4. quints-0.20.0/src/quints/invoice/epc.py +61 -0
  5. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/labels.py +18 -0
  6. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/model.py +1 -0
  7. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/qr.py +11 -0
  8. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/render.py +117 -22
  9. quints-0.20.0/src/quints/invoice/template.typ +269 -0
  10. quints-0.20.0/tests/conftest.py +9 -0
  11. {quints-0.19.0 → quints-0.20.0}/tests/test_cli_json.py +27 -0
  12. {quints-0.19.0 → quints-0.20.0}/tests/test_init.py +1 -1
  13. {quints-0.19.0 → quints-0.20.0}/tests/test_invoice.py +72 -1
  14. quints-0.19.0/src/quints/invoice/template.typ +0 -222
  15. {quints-0.19.0 → quints-0.20.0}/.gitignore +0 -0
  16. {quints-0.19.0 → quints-0.20.0}/LICENSE +0 -0
  17. {quints-0.19.0 → quints-0.20.0}/README.md +0 -0
  18. {quints-0.19.0 → quints-0.20.0}/examples/.gitignore +0 -0
  19. {quints-0.19.0 → quints-0.20.0}/examples/AGENTS.md +0 -0
  20. {quints-0.19.0 → quints-0.20.0}/examples/CLAUDE.md +0 -0
  21. {quints-0.19.0 → quints-0.20.0}/examples/accounts.bean +0 -0
  22. {quints-0.19.0 → quints-0.20.0}/examples/answers.toml +0 -0
  23. {quints-0.19.0 → quints-0.20.0}/examples/books/2026.bean +0 -0
  24. {quints-0.19.0 → quints-0.20.0}/examples/commodities.bean +0 -0
  25. {quints-0.19.0 → quints-0.20.0}/examples/documents/.gitkeep +0 -0
  26. {quints-0.19.0 → quints-0.20.0}/examples/inbox/.gitkeep +0 -0
  27. {quints-0.19.0 → quints-0.20.0}/examples/invoicing/acme-2026-07.yaml +0 -0
  28. {quints-0.19.0 → quints-0.20.0}/examples/invoicing/customers.yaml +0 -0
  29. {quints-0.19.0 → quints-0.20.0}/examples/invoicing/globex-2026-08.yaml +0 -0
  30. {quints-0.19.0 → quints-0.20.0}/examples/invoicing/issuer.yaml +0 -0
  31. {quints-0.19.0 → quints-0.20.0}/examples/invoicing/wordmark.svg +0 -0
  32. {quints-0.19.0 → quints-0.20.0}/examples/main.bean +0 -0
  33. {quints-0.19.0 → quints-0.20.0}/examples/prices.bean +0 -0
  34. {quints-0.19.0 → quints-0.20.0}/examples/pyproject.toml +0 -0
  35. {quints-0.19.0 → quints-0.20.0}/examples/quints.toml +0 -0
  36. {quints-0.19.0 → quints-0.20.0}/examples/staging/.gitkeep +0 -0
  37. {quints-0.19.0 → quints-0.20.0}/examples/statements/ubs-2026.mt940 +0 -0
  38. {quints-0.19.0 → quints-0.20.0}/examples/statements/yapeal.csv +0 -0
  39. {quints-0.19.0 → quints-0.20.0}/src/quints/__init__.py +0 -0
  40. {quints-0.19.0 → quints-0.20.0}/src/quints/closing.py +0 -0
  41. {quints-0.19.0 → quints-0.20.0}/src/quints/config.py +0 -0
  42. {quints-0.19.0 → quints-0.20.0}/src/quints/fava/__init__.py +0 -0
  43. {quints-0.19.0 → quints-0.20.0}/src/quints/fava/templates/QuintDashboard.html +0 -0
  44. {quints-0.19.0 → quints-0.20.0}/src/quints/fx.py +0 -0
  45. {quints-0.19.0 → quints-0.20.0}/src/quints/importing.py +0 -0
  46. {quints-0.19.0 → quints-0.20.0}/src/quints/inbox.py +0 -0
  47. {quints-0.19.0 → quints-0.20.0}/src/quints/init.py +0 -0
  48. {quints-0.19.0 → quints-0.20.0}/src/quints/init_assets/wordmark.svg +0 -0
  49. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/__init__.py +0 -0
  50. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/bank.py +0 -0
  51. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/draft.py +0 -0
  52. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/README.md +0 -0
  53. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/geist/Geist-Bold.otf +0 -0
  54. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/geist/Geist-Medium.otf +0 -0
  55. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/geist/Geist-Regular.otf +0 -0
  56. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/geist/Geist-SemiBold.otf +0 -0
  57. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/geist/OFL.txt +0 -0
  58. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/geist-mono/GeistMono-Medium.otf +0 -0
  59. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/geist-mono/GeistMono-Regular.otf +0 -0
  60. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/geist-mono/GeistMono-SemiBold.otf +0 -0
  61. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/geist-mono/OFL.txt +0 -0
  62. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/liberation/LICENSE +0 -0
  63. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/liberation/LiberationSans-Bold.ttf +0 -0
  64. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/liberation/LiberationSans-Regular.ttf +0 -0
  65. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/newsreader/Newsreader-Medium.ttf +0 -0
  66. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/newsreader/Newsreader-Regular.ttf +0 -0
  67. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/newsreader/Newsreader-SemiBold.ttf +0 -0
  68. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/fonts/newsreader/OFL.txt +0 -0
  69. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/reference.py +0 -0
  70. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/swico.py +0 -0
  71. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/vatid.py +0 -0
  72. {quints-0.19.0 → quints-0.20.0}/src/quints/invoice/verify.py +0 -0
  73. {quints-0.19.0 → quints-0.20.0}/src/quints/kmu.py +0 -0
  74. {quints-0.19.0 → quints-0.20.0}/src/quints/ledger.py +0 -0
  75. {quints-0.19.0 → quints-0.20.0}/src/quints/liability.py +0 -0
  76. {quints-0.19.0 → quints-0.20.0}/src/quints/match.py +0 -0
  77. {quints-0.19.0 → quints-0.20.0}/src/quints/mwst.py +0 -0
  78. {quints-0.19.0 → quints-0.20.0}/src/quints/payables.py +0 -0
  79. {quints-0.19.0 → quints-0.20.0}/src/quints/plugins/__init__.py +0 -0
  80. {quints-0.19.0 → quints-0.20.0}/src/quints/plugins/kmu.py +0 -0
  81. {quints-0.19.0 → quints-0.20.0}/src/quints/prices.py +0 -0
  82. {quints-0.19.0 → quints-0.20.0}/src/quints/receivables.py +0 -0
  83. {quints-0.19.0 → quints-0.20.0}/src/quints/report.typ +0 -0
  84. {quints-0.19.0 → quints-0.20.0}/src/quints/report_pdf.py +0 -0
  85. {quints-0.19.0 → quints-0.20.0}/src/quints/settlement.py +0 -0
  86. {quints-0.19.0 → quints-0.20.0}/src/quints/ui.py +0 -0
  87. {quints-0.19.0 → quints-0.20.0}/src/quints/vat.py +0 -0
  88. {quints-0.19.0 → quints-0.20.0}/tests/fixtures/transactions.mt940 +0 -0
  89. {quints-0.19.0 → quints-0.20.0}/tests/test_cli_errors.py +0 -0
  90. {quints-0.19.0 → quints-0.20.0}/tests/test_closing.py +0 -0
  91. {quints-0.19.0 → quints-0.20.0}/tests/test_config.py +0 -0
  92. {quints-0.19.0 → quints-0.20.0}/tests/test_config_strict.py +0 -0
  93. {quints-0.19.0 → quints-0.20.0}/tests/test_docs.py +0 -0
  94. {quints-0.19.0 → quints-0.20.0}/tests/test_durable_writes.py +0 -0
  95. {quints-0.19.0 → quints-0.20.0}/tests/test_fava_ext.py +0 -0
  96. {quints-0.19.0 → quints-0.20.0}/tests/test_fx.py +0 -0
  97. {quints-0.19.0 → quints-0.20.0}/tests/test_importing.py +0 -0
  98. {quints-0.19.0 → quints-0.20.0}/tests/test_importing_stripe_invoices.py +0 -0
  99. {quints-0.19.0 → quints-0.20.0}/tests/test_inbox_match.py +0 -0
  100. {quints-0.19.0 → quints-0.20.0}/tests/test_kmu_plugin.py +0 -0
  101. {quints-0.19.0 → quints-0.20.0}/tests/test_kmu_report.py +0 -0
  102. {quints-0.19.0 → quints-0.20.0}/tests/test_ledger.py +0 -0
  103. {quints-0.19.0 → quints-0.20.0}/tests/test_loader_errors.py +0 -0
  104. {quints-0.19.0 → quints-0.20.0}/tests/test_money_defaults.py +0 -0
  105. {quints-0.19.0 → quints-0.20.0}/tests/test_mwst.py +0 -0
  106. {quints-0.19.0 → quints-0.20.0}/tests/test_payables.py +0 -0
  107. {quints-0.19.0 → quints-0.20.0}/tests/test_prices_ecosystem.py +0 -0
  108. {quints-0.19.0 → quints-0.20.0}/tests/test_prices_sync.py +0 -0
  109. {quints-0.19.0 → quints-0.20.0}/tests/test_proforma.py +0 -0
  110. {quints-0.19.0 → quints-0.20.0}/tests/test_receivables.py +0 -0
  111. {quints-0.19.0 → quints-0.20.0}/tests/test_report_pdf.py +0 -0
  112. {quints-0.19.0 → quints-0.20.0}/tests/test_saldo.py +0 -0
  113. {quints-0.19.0 → quints-0.20.0}/tests/test_settlement.py +0 -0
  114. {quints-0.19.0 → quints-0.20.0}/tests/test_statements_crosscheck.py +0 -0
  115. {quints-0.19.0 → quints-0.20.0}/tests/test_vat_lifecycle.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: quints
3
- Version: 0.19.0
3
+ Version: 0.20.0
4
4
  Summary: Swiss VAT & accounting toolkit for plain-text (beancount) books: MWST reports and quarterly settlement, Bezugsteuer helpers, BAZG daily FX rates, QR-bill invoicing, KMU statutory statements, and statement importers (UBS MT940, Yapeal, Wise, Stripe) that draft into a staging area
5
5
  License: GPL-2.0-only
6
6
  License-File: LICENSE
@@ -18,6 +18,7 @@ Requires-Dist: pydantic>=2.7
18
18
  Requires-Dist: python-stdnum>=1.20
19
19
  Requires-Dist: pyyaml>=6.0.3
20
20
  Requires-Dist: qrbill>=1.2.0
21
+ Requires-Dist: qrcode>=8.0
21
22
  Requires-Dist: rich>=13
22
23
  Requires-Dist: tomli>=2; python_version < '3.11'
23
24
  Requires-Dist: typer>=0.12
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "quints"
3
- version = "0.19.0"
3
+ version = "0.20.0"
4
4
  description = "Swiss VAT & accounting toolkit for plain-text (beancount) books: MWST reports and quarterly settlement, Bezugsteuer helpers, BAZG daily FX rates, QR-bill invoicing, KMU statutory statements, and statement importers (UBS MT940, Yapeal, Wise, Stripe) that draft into a staging area"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.10"
@@ -22,6 +22,7 @@ dependencies = [
22
22
  "python-stdnum>=1.20",
23
23
  "pyyaml>=6.0.3",
24
24
  "qrbill>=1.2.0",
25
+ "qrcode>=8.0",
25
26
  "rich>=13",
26
27
  "tomli>=2; python_version < '3.11'",
27
28
  "typer>=0.12",
@@ -863,10 +863,13 @@ def invoice(
863
863
 
864
864
 
865
865
  def _qr_payload_ok(payload: str | None) -> bool | None:
866
- """SPC first, EPD present — or, after it, the Swico billing information."""
866
+ """QR-bill: SPC first, EPD present — or, after it, the Swico billing
867
+ information. EPC QR (EUR export): BCD first, SCT fourth."""
867
868
  if not payload:
868
869
  return None
869
870
  lines = payload.splitlines()
871
+ if lines[:1] == ["BCD"]:
872
+ return lines[3:4] == ["SCT"]
870
873
  return lines[:1] == ["SPC"] and "EPD" in lines
871
874
 
872
875
 
@@ -922,8 +925,9 @@ def _print_rendered(
922
925
  f"[muted]not VAT-registered on {inv.issue_date}: no VAT charged or shown[/]"
923
926
  )
924
927
  if payload:
928
+ name, shape = ("EPC QR", "BCD…SCT") if payload.startswith("BCD") else ("QR-bill", "SPC…EPD")
925
929
  ui.console.print(
926
- f"[muted]QR-bill payload: {'SPC…EPD ✓' if qr_ok else 'CHECK!'} "
930
+ f"[muted]{name} payload: {f'{shape} ✓' if qr_ok else 'CHECK!'} "
927
931
  f"({len(payload.splitlines())} lines)[/]"
928
932
  )
929
933
 
@@ -0,0 +1,61 @@
1
+ """EPC QR code for a SEPA credit transfer in EUR (EPC069-12 v3.1).
2
+
3
+ The export invoice's scan-to-pay code: the payer's banking app reads it and
4
+ pre-fills the transfer. EPC069-12 is written for exactly this case — the same
5
+ data printed beside it in plain text, so the payer can compare the two."""
6
+
7
+ from __future__ import annotations
8
+
9
+ from decimal import Decimal
10
+ from pathlib import Path
11
+
12
+ import qrcode
13
+ from qrcode.constants import ERROR_CORRECT_M
14
+ from qrcode.image.svg import SvgPathFillImage
15
+
16
+ from .reference import PaymentReference
17
+
18
+ MAX_BYTES = 331 # §2.2: QR version 13 at error level M
19
+ MAX_NAME = 70
20
+ MAX_AMOUNT = Decimal("999999999.99")
21
+
22
+
23
+ def payload(name: str, iban: str, bic: str, amount: Decimal, ref: PaymentReference) -> str:
24
+ """The `BCD` payload, version 002, UTF-8. The BIC is always included: the
25
+ guidelines keep it mandatory for SCT participants outside the EEA, which
26
+ every Swiss account is."""
27
+ if len(name) > MAX_NAME:
28
+ # Truncating would change the name the payer's bank checks the IBAN against.
29
+ raise ValueError(
30
+ f"beneficiary {name!r} is longer than the {MAX_NAME} characters an "
31
+ f"EPC QR code carries — set a shorter `holder` on the account, exactly "
32
+ f"as the bank holds it"
33
+ )
34
+ if not Decimal("0.01") <= amount <= MAX_AMOUNT:
35
+ raise ValueError(f"an EPC QR code carries EUR 0.01 to {MAX_AMOUNT}, not {amount}")
36
+ if ref.kind != "SCOR":
37
+ raise ValueError(f"an EPC QR code takes an RF creditor reference, not {ref.kind}")
38
+ lines = [
39
+ "BCD",
40
+ "002",
41
+ "1", # UTF-8
42
+ "SCT",
43
+ bic,
44
+ name,
45
+ iban,
46
+ f"EUR{amount:.2f}",
47
+ "", # purpose code
48
+ ref.value, # structured remittance: the ISO 11649 RF reference
49
+ ]
50
+ data = "\n".join(lines)
51
+ if len(data.encode()) > MAX_BYTES:
52
+ raise ValueError(f"EPC QR payload is {len(data.encode())} bytes, over {MAX_BYTES}")
53
+ return data
54
+
55
+
56
+ def write_svg(data: str, path: Path) -> None:
57
+ qr = qrcode.QRCode(error_correction=ERROR_CORRECT_M, image_factory=SvgPathFillImage)
58
+ qr.add_data(data)
59
+ qr.make(fit=True)
60
+ with path.open("wb") as f:
61
+ qr.make_image().save(f)
@@ -17,6 +17,9 @@ LABELS = {
17
17
  "invoice": "Rechnung",
18
18
  "invoice_no": "Rechnungs-Nr.",
19
19
  "date": "Rechnungsdatum",
20
+ "due_date": "Zahlbar bis",
21
+ "customer_vat": "MWST-Nr. Kunde",
22
+ "amount": "Betrag",
20
23
  "supply": "Leistungsperiode",
21
24
  "your_reference": "Ihre Referenz",
22
25
  "pos": "Pos.",
@@ -32,6 +35,9 @@ LABELS = {
32
35
  "beneficiary": "Begünstigter",
33
36
  "bank": "Bank",
34
37
  "reference": "Referenz",
38
+ "scan_to_pay": "Mit der Banking-App scannen",
39
+ "qr_bill": "QR-Rechnung",
40
+ "made_with": "Erstellt mit quints",
35
41
  "terms": "Zahlbar innert {days} Tagen netto.",
36
42
  "export_note": "Nicht der schweizerischen MWST unterliegend: Ort der "
37
43
  "Leistung im Ausland (Art. 8 Abs. 1 MWSTG).",
@@ -50,6 +56,9 @@ LABELS = {
50
56
  "invoice": "Invoice",
51
57
  "invoice_no": "Invoice no.",
52
58
  "date": "Invoice date",
59
+ "due_date": "Due date",
60
+ "customer_vat": "Customer VAT no.",
61
+ "amount": "Amount",
53
62
  "supply": "Service period",
54
63
  "your_reference": "Your reference",
55
64
  "pos": "No.",
@@ -65,6 +74,9 @@ LABELS = {
65
74
  "beneficiary": "Beneficiary",
66
75
  "bank": "Bank",
67
76
  "reference": "Reference",
77
+ "scan_to_pay": "Scan with your banking app",
78
+ "qr_bill": "QR-bill",
79
+ "made_with": "Made with quints",
68
80
  "terms": "Payable within {days} days net.",
69
81
  "export_note": "Not subject to Swiss VAT: place of supply abroad "
70
82
  "(Art. 8 para. 1 Swiss VAT Act).",
@@ -83,6 +95,9 @@ LABELS = {
83
95
  "invoice": "Factura",
84
96
  "invoice_no": "N.º de factura",
85
97
  "date": "Fecha de factura",
98
+ "due_date": "Vencimiento",
99
+ "customer_vat": "NIF-IVA del cliente",
100
+ "amount": "Importe",
86
101
  "supply": "Periodo de servicio",
87
102
  "your_reference": "Su referencia",
88
103
  "pos": "N.º",
@@ -98,6 +113,9 @@ LABELS = {
98
113
  "beneficiary": "Beneficiario",
99
114
  "bank": "Banco",
100
115
  "reference": "Referencia",
116
+ "scan_to_pay": "Escanee con la app de su banco",
117
+ "qr_bill": "Factura QR",
118
+ "made_with": "Hecho con quints",
101
119
  "terms": "A pagar en un plazo de {days} días netos.",
102
120
  "export_note": "No sujeto al IVA suizo: lugar de la prestación en el "
103
121
  "extranjero (art. 8 apdo. 1 de la Ley suiza del IVA).",
@@ -615,6 +615,7 @@ class Brand(BaseModel):
615
615
  font_dir: str | None = None # bundled fonts dir passed to typst (repo-relative)
616
616
  logo: str | None = None
617
617
  logo_height: float = 12.0 # mm, as placed in the header
618
+ credit: bool = True # the small "Made with quints" line under the body; false drops it
618
619
 
619
620
  ink: HexColor = "#1c1618" # body copy
620
621
  subtle: HexColor = "#655753" # labels and secondary text
@@ -6,6 +6,7 @@ import re
6
6
  import warnings
7
7
  from collections.abc import Sequence
8
8
  from pathlib import Path
9
+ from typing import Literal
9
10
 
10
11
  from qrbill import QRBill
11
12
 
@@ -13,6 +14,15 @@ from . import reference as ref_mod
13
14
  from . import swico
14
15
  from .model import BankAccount, Invoice, Issuer, Totals
15
16
 
17
+ # The languages the Implementation Guidelines print the payment part in; any
18
+ # other invoice language gets the English slip.
19
+ _SLIP_LANGUAGES: dict[str, Literal["en", "de", "fr", "it"]] = {
20
+ "en": "en",
21
+ "de": "de",
22
+ "fr": "fr",
23
+ "it": "it",
24
+ }
25
+
16
26
 
17
27
  def _structured(name: str, lines: Sequence[str], country: str) -> dict[str, str | None]:
18
28
  """Parse free-form address lines into qrbill's structured address dict."""
@@ -78,6 +88,7 @@ def build_bill(inv: Invoice, issuer: Issuer, account: BankAccount, totals: Total
78
88
  reference_number=payment_ref.value,
79
89
  additional_information=message,
80
90
  billing_information=billing,
91
+ language=_SLIP_LANGUAGES.get(inv.language, "en"),
81
92
  )
82
93
  # The Implementation Guidelines allow Arial, Frutiger, Helvetica and
83
94
  # Liberation Sans in the payment part, and nothing else. qrbill asks for
@@ -7,14 +7,16 @@ import re
7
7
  import shutil
8
8
  import tempfile
9
9
  from collections.abc import Mapping
10
- from datetime import date
10
+ from datetime import date, datetime, timedelta, timezone
11
+ from decimal import Decimal
11
12
  from pathlib import Path
12
13
  from typing import TypedDict
13
14
 
14
15
  import typst
16
+ from babel import Locale
15
17
  from babel.dates import format_date
16
18
 
17
- from . import bank, qr
19
+ from . import bank, epc, qr
18
20
  from . import reference as ref_mod
19
21
  from .labels import labels as get_labels
20
22
  from .model import (
@@ -44,6 +46,8 @@ class InvoiceContext(TypedDict):
44
46
  reverse_charge: bool
45
47
  proforma: bool
46
48
  lang: str
49
+ region: str | None
50
+ document: dict[str, str | list[str]]
47
51
  kind: str
48
52
  currency: str
49
53
  labels: dict[str, str]
@@ -57,7 +61,7 @@ class InvoiceContext(TypedDict):
57
61
  totals: dict[str, str | bool]
58
62
  payment: Mapping[str, str | None]
59
63
  notes: list[str]
60
- brand: dict[str, str | float | None]
64
+ brand: dict[str, str | float | bool | None]
61
65
 
62
66
 
63
67
  def _fmt_date(d: date, locale: str) -> str:
@@ -85,10 +89,25 @@ def build_context(
85
89
  "grand_total": lbl["amount_due"],
86
90
  }
87
91
  customer = inv.resolved_customer
92
+ references = [
93
+ *(
94
+ [{"label": lbl["your_reference"], "value": inv.customer_reference}]
95
+ if inv.customer_reference
96
+ else []
97
+ ),
98
+ *({"label": r.label, "value": r.value} for r in inv.references),
99
+ ]
100
+ due = (
101
+ _fmt_date(inv.issue_date + timedelta(days=inv.terms_days), inv.locale)
102
+ if inv.terms_days is not None and totals.amount_due
103
+ else ""
104
+ )
88
105
  return {
89
106
  "proforma": inv.proforma,
90
107
  "reverse_charge": reverse_charge,
91
108
  "lang": inv.language,
109
+ "region": Locale.parse(inv.locale).territory,
110
+ "document": _document_metadata(inv, issuer, totals, lbl, payment, references),
92
111
  "kind": inv.kind,
93
112
  "currency": inv.currency,
94
113
  "labels": lbl,
@@ -104,23 +123,21 @@ def build_context(
104
123
  "name": customer.name,
105
124
  "address": customer.address,
106
125
  "country": customer.country,
126
+ # Postal convention: the country spelled out, in capitals, last line.
127
+ "country_name": Locale.parse(inv.locale)
128
+ .territories.get(customer.country, customer.country)
129
+ .upper(),
107
130
  "vat_id": customer.vat_id,
108
131
  },
109
132
  "invoice": {
110
133
  "number": inv.number,
111
134
  "supply": inv.supply.text(inv.locale),
112
135
  "issue_date": _fmt_date(inv.issue_date, inv.locale),
136
+ "due_date": due,
113
137
  },
114
138
  # The customer's own reference, then whatever else their side demands —
115
139
  # printed in the title meta grid, under the invoice number and date.
116
- "references": [
117
- *(
118
- [{"label": lbl["your_reference"], "value": inv.customer_reference}]
119
- if inv.customer_reference
120
- else []
121
- ),
122
- *({"label": r.label, "value": r.value} for r in inv.references),
123
- ],
140
+ "references": references,
124
141
  "terms": (
125
142
  lbl["terms"].format(days=inv.terms_days)
126
143
  if inv.terms_days is not None and totals.amount_due
@@ -152,6 +169,41 @@ def build_context(
152
169
  }
153
170
 
154
171
 
172
+ def _document_metadata(
173
+ inv: Invoice,
174
+ issuer: Issuer,
175
+ totals: Totals,
176
+ lbl: Mapping[str, str],
177
+ payment: Mapping[str, str | None],
178
+ references: list[dict[str, str]],
179
+ ) -> dict[str, str | list[str]]:
180
+ """The PDF's title, subject and keywords — what a mail client, file browser
181
+ or the payer's accounts-payable system shows and indexes without opening
182
+ the page. The title leads with the issuer: it is the tab title, and how a
183
+ payer tells one supplier's PDF from the next."""
184
+ due_label = lbl["amount_due"] if inv.advances else lbl["grand_total"]
185
+ parts = [
186
+ f"{lbl['invoice']} {inv.number}",
187
+ inv.resolved_customer.name,
188
+ f"{lbl['supply']} {inv.supply.text(inv.locale)}",
189
+ f"{due_label} {inv.currency} {money(totals.amount_due, inv.locale)}",
190
+ ]
191
+ if inv.terms_days is not None and totals.amount_due:
192
+ due = inv.issue_date + timedelta(days=inv.terms_days)
193
+ parts.append(f"{lbl['due_date']} {_fmt_date(due, inv.locale)}")
194
+ parts.append(lbl["terms"].format(days=inv.terms_days))
195
+ # Identifiers only: what a payer searches or matches the invoice on. The
196
+ # payment reference compact, as it comes back on the bank statement.
197
+ keywords = [inv.number, *(r["value"] for r in references)]
198
+ if payment.get("reference"):
199
+ keywords.append(str(payment["reference"]).replace(" ", ""))
200
+ return {
201
+ "title": f"{issuer.name} – {lbl['invoice']} {inv.number}",
202
+ "description": " · ".join(parts),
203
+ "keywords": keywords,
204
+ }
205
+
206
+
155
207
  def _advance_label(inv: Invoice, lbl: Mapping[str, str], a: Advance, totals: Totals) -> str:
156
208
  """The pro forma showed the advance's VAT, and the invoice shows VAT on the
157
209
  whole supply: naming the VAT credited back keeps it from reading as shown
@@ -179,7 +231,7 @@ def _totals_context(inv: Invoice, totals: Totals) -> dict[str, str | bool]:
179
231
  }
180
232
 
181
233
 
182
- def _brand_context(issuer: Issuer, logo: str | None) -> dict[str, str | float | None]:
234
+ def _brand_context(issuer: Issuer, logo: str | None) -> dict[str, str | float | bool | None]:
183
235
  brand = issuer.brand
184
236
  return {
185
237
  "accent": brand.accent,
@@ -194,14 +246,24 @@ def _brand_context(issuer: Issuer, logo: str | None) -> dict[str, str | float |
194
246
  "panel": brand.panel,
195
247
  "logo": logo,
196
248
  "logo_height": brand.logo_height,
249
+ "credit": brand.credit,
197
250
  }
198
251
 
199
252
 
200
253
  def _compile(
201
- main: Path, output: Path, root: Path, font_paths: list[Path], only_bundled: bool
254
+ main: Path,
255
+ output: Path,
256
+ root: Path,
257
+ font_paths: list[Path],
258
+ only_bundled: bool,
259
+ issued: date,
202
260
  ) -> None:
203
- """Compile to PDF/A-2b (archival) — never a silent plain-PDF fallback: an
261
+ """Compile to PDF/A-2a + PDF/UA-1 — never a silent plain-PDF fallback: an
204
262
  invoice is kept, readable, for ten years (Art. 958f OR, Art. 70 MWSTG).
263
+ Level A (tagged, Unicode text, alt text on every image) over B: the archive
264
+ copy stays searchable and its text extractable, and the payer's screen
265
+ reader can read it. Not A-3: its only addition is embedded files, which
266
+ only matters once a machine-readable invoice (Factur-X/ZUGFeRD) rides along.
205
267
 
206
268
  `only_bundled` switches machine-installed families off. Without it, a
207
269
  variable font installed on the designer's machine shadows the bundled (or
@@ -209,6 +271,10 @@ def _compile(
209
271
  collapses to the variable font's default instance, so the same invoice
210
272
  renders differently on a colleague's machine. Only an issuer who names a
211
273
  family that neither we nor they ship keeps system fonts on.
274
+
275
+ The PDF is dated the issue date, not the moment of rendering: the same
276
+ invoice then renders to the same bytes, so an archived copy can be checked
277
+ by rendering it again.
212
278
  """
213
279
  typst.compile(
214
280
  str(main),
@@ -216,7 +282,10 @@ def _compile(
216
282
  root=str(root),
217
283
  font_paths=[str(p) for p in font_paths],
218
284
  ignore_system_fonts=only_bundled,
219
- pdf_standards="a-2b",
285
+ pdf_standards=["a-2a", "ua-1"],
286
+ timestamp=int(
287
+ datetime(issued.year, issued.month, issued.day, tzinfo=timezone.utc).timestamp()
288
+ ),
220
289
  )
221
290
 
222
291
 
@@ -266,8 +335,11 @@ def _reverse_charge(inv: Invoice) -> bool:
266
335
  return reverse_charge
267
336
 
268
337
 
269
- def _sepa_payment(inv: Invoice, issuer: Issuer, account: BankAccount) -> dict[str, str | None]:
270
- """The cross-border payment block: IBAN, BIC and reference."""
338
+ def _sepa_payment(
339
+ inv: Invoice, issuer: Issuer, account: BankAccount, amount: Decimal
340
+ ) -> dict[str, str | None]:
341
+ """The cross-border payment block: IBAN, BIC and reference — plus, in EUR,
342
+ the EPC QR payload that pre-fills the same transfer in a banking app."""
271
343
  # Cross-border: a QR-IBAN only works inside the QR-bill scheme —
272
344
  # foreign transfers need the regular IBAN.
273
345
  if not account.iban:
@@ -287,13 +359,24 @@ def _sepa_payment(inv: Invoice, issuer: Issuer, account: BankAccount) -> dict[st
287
359
  f"bank.{inv.currency} in the issuer config; "
288
360
  f"`quints iban {account.iban}` shows what to ask the bank for"
289
361
  )
362
+ beneficiary = account.holder or issuer.name
363
+ ref = ref_mod.payment_reference(inv, account)
364
+ # The EPC code is SEPA credit transfers in euro only; anything else is
365
+ # paid from the printed fields.
366
+ scan = inv.currency == "EUR" and amount > 0
367
+ lbl = get_labels(inv.language)
290
368
  return {
291
369
  "type": "sepa",
292
- "beneficiary": account.holder or issuer.name,
370
+ "beneficiary": beneficiary,
293
371
  "iban": bank.format_iban(account.iban),
294
372
  "bic": account.bic,
295
373
  "bank_name": account.bank_name,
296
- "reference": ref_mod.payment_reference(inv, account).formatted,
374
+ "reference": ref.formatted,
375
+ "epc": epc.payload(beneficiary, account.iban, account.bic, amount, ref) if scan else None,
376
+ # What the code pre-fills, for whoever cannot scan it.
377
+ "alt": f"{lbl['scan_to_pay']} · {inv.currency} {money(amount, inv.locale)}"
378
+ f" · {lbl['payment_to']} {beneficiary} · IBAN {bank.format_iban(account.iban)}"
379
+ f" · {lbl['reference']} {ref.formatted}",
297
380
  }
298
381
 
299
382
 
@@ -330,9 +413,21 @@ def render(
330
413
  bill = qr.build_bill(inv, issuer, account, totals)
331
414
  qr.write_svg(bill, work / "qrbill.svg")
332
415
  qr_payload = qr.payload(bill)
333
- payment = {"type": "qrbill"}
416
+ ref = ref_mod.payment_reference(inv, account).formatted
417
+ lbl = get_labels(inv.language)
418
+ # The payment part is an image: its alt text is the only way a
419
+ # screen reader, or text extraction, gets at what it says.
420
+ alt = (
421
+ f"{lbl['qr_bill']} · {inv.currency} {money(totals.amount_due, inv.locale)}"
422
+ f" · {lbl['payment_to']} {account.holder or issuer.name}"
423
+ f" · IBAN {bank.format_iban(bill.account)} · {lbl['reference']} {ref}"
424
+ )
425
+ payment = {"type": "qrbill", "reference": ref, "alt": alt}
334
426
  else:
335
- payment = _sepa_payment(inv, issuer, account)
427
+ payment = _sepa_payment(inv, issuer, account, totals.amount_due)
428
+ qr_payload = payment["epc"]
429
+ if qr_payload:
430
+ epc.write_svg(qr_payload, work / "epc.svg")
336
431
 
337
432
  logo = issuer.brand.logo
338
433
  logo_name = None
@@ -348,7 +443,7 @@ def render(
348
443
  font_paths, only_bundled = _fonts(issuer)
349
444
  out_path = Path(out_path)
350
445
  out_path.parent.mkdir(parents=True, exist_ok=True)
351
- _compile(work / "template.typ", out_path, work, font_paths, only_bundled)
446
+ _compile(work / "template.typ", out_path, work, font_paths, only_bundled, inv.issue_date)
352
447
  return out_path, totals, qr_payload
353
448
  finally:
354
449
  shutil.rmtree(work, ignore_errors=True)