quints 0.18.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 (117) hide show
  1. {quints-0.18.0 → quints-0.20.0}/PKG-INFO +2 -1
  2. {quints-0.18.0 → quints-0.20.0}/examples/AGENTS.md +8 -0
  3. {quints-0.18.0 → quints-0.20.0}/examples/accounts.bean +4 -0
  4. {quints-0.18.0 → quints-0.20.0}/examples/quints.toml +2 -0
  5. {quints-0.18.0 → quints-0.20.0}/pyproject.toml +2 -1
  6. {quints-0.18.0 → quints-0.20.0}/src/quints/cli.py +65 -28
  7. {quints-0.18.0 → quints-0.20.0}/src/quints/config.py +21 -0
  8. {quints-0.18.0 → quints-0.20.0}/src/quints/fx.py +2 -0
  9. {quints-0.18.0 → quints-0.20.0}/src/quints/init.py +14 -0
  10. quints-0.20.0/src/quints/invoice/draft.py +151 -0
  11. quints-0.20.0/src/quints/invoice/epc.py +61 -0
  12. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/labels.py +49 -2
  13. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/model.py +59 -0
  14. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/qr.py +27 -4
  15. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/render.py +176 -39
  16. quints-0.20.0/src/quints/invoice/template.typ +269 -0
  17. quints-0.20.0/src/quints/invoice/verify.py +198 -0
  18. {quints-0.18.0 → quints-0.20.0}/src/quints/kmu.py +15 -3
  19. {quints-0.18.0 → quints-0.20.0}/src/quints/mwst.py +21 -2
  20. {quints-0.18.0 → quints-0.20.0}/src/quints/report.typ +32 -9
  21. {quints-0.18.0 → quints-0.20.0}/src/quints/report_pdf.py +80 -13
  22. quints-0.20.0/tests/conftest.py +9 -0
  23. {quints-0.18.0 → quints-0.20.0}/tests/test_cli_json.py +27 -0
  24. {quints-0.18.0 → quints-0.20.0}/tests/test_init.py +1 -1
  25. {quints-0.18.0 → quints-0.20.0}/tests/test_invoice.py +84 -1
  26. {quints-0.18.0 → quints-0.20.0}/tests/test_kmu_report.py +19 -2
  27. quints-0.20.0/tests/test_proforma.py +485 -0
  28. {quints-0.18.0 → quints-0.20.0}/tests/test_report_pdf.py +32 -0
  29. quints-0.18.0/src/quints/invoice/draft.py +0 -60
  30. quints-0.18.0/src/quints/invoice/template.typ +0 -206
  31. quints-0.18.0/src/quints/invoice/verify.py +0 -66
  32. {quints-0.18.0 → quints-0.20.0}/.gitignore +0 -0
  33. {quints-0.18.0 → quints-0.20.0}/LICENSE +0 -0
  34. {quints-0.18.0 → quints-0.20.0}/README.md +0 -0
  35. {quints-0.18.0 → quints-0.20.0}/examples/.gitignore +0 -0
  36. {quints-0.18.0 → quints-0.20.0}/examples/CLAUDE.md +0 -0
  37. {quints-0.18.0 → quints-0.20.0}/examples/answers.toml +0 -0
  38. {quints-0.18.0 → quints-0.20.0}/examples/books/2026.bean +0 -0
  39. {quints-0.18.0 → quints-0.20.0}/examples/commodities.bean +0 -0
  40. {quints-0.18.0 → quints-0.20.0}/examples/documents/.gitkeep +0 -0
  41. {quints-0.18.0 → quints-0.20.0}/examples/inbox/.gitkeep +0 -0
  42. {quints-0.18.0 → quints-0.20.0}/examples/invoicing/acme-2026-07.yaml +0 -0
  43. {quints-0.18.0 → quints-0.20.0}/examples/invoicing/customers.yaml +0 -0
  44. {quints-0.18.0 → quints-0.20.0}/examples/invoicing/globex-2026-08.yaml +0 -0
  45. {quints-0.18.0 → quints-0.20.0}/examples/invoicing/issuer.yaml +0 -0
  46. {quints-0.18.0 → quints-0.20.0}/examples/invoicing/wordmark.svg +0 -0
  47. {quints-0.18.0 → quints-0.20.0}/examples/main.bean +0 -0
  48. {quints-0.18.0 → quints-0.20.0}/examples/prices.bean +0 -0
  49. {quints-0.18.0 → quints-0.20.0}/examples/pyproject.toml +0 -0
  50. {quints-0.18.0 → quints-0.20.0}/examples/staging/.gitkeep +0 -0
  51. {quints-0.18.0 → quints-0.20.0}/examples/statements/ubs-2026.mt940 +0 -0
  52. {quints-0.18.0 → quints-0.20.0}/examples/statements/yapeal.csv +0 -0
  53. {quints-0.18.0 → quints-0.20.0}/src/quints/__init__.py +0 -0
  54. {quints-0.18.0 → quints-0.20.0}/src/quints/closing.py +0 -0
  55. {quints-0.18.0 → quints-0.20.0}/src/quints/fava/__init__.py +0 -0
  56. {quints-0.18.0 → quints-0.20.0}/src/quints/fava/templates/QuintDashboard.html +0 -0
  57. {quints-0.18.0 → quints-0.20.0}/src/quints/importing.py +0 -0
  58. {quints-0.18.0 → quints-0.20.0}/src/quints/inbox.py +0 -0
  59. {quints-0.18.0 → quints-0.20.0}/src/quints/init_assets/wordmark.svg +0 -0
  60. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/__init__.py +0 -0
  61. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/bank.py +0 -0
  62. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/README.md +0 -0
  63. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/geist/Geist-Bold.otf +0 -0
  64. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/geist/Geist-Medium.otf +0 -0
  65. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/geist/Geist-Regular.otf +0 -0
  66. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/geist/Geist-SemiBold.otf +0 -0
  67. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/geist/OFL.txt +0 -0
  68. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/geist-mono/GeistMono-Medium.otf +0 -0
  69. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/geist-mono/GeistMono-Regular.otf +0 -0
  70. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/geist-mono/GeistMono-SemiBold.otf +0 -0
  71. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/geist-mono/OFL.txt +0 -0
  72. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/liberation/LICENSE +0 -0
  73. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/liberation/LiberationSans-Bold.ttf +0 -0
  74. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/liberation/LiberationSans-Regular.ttf +0 -0
  75. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/newsreader/Newsreader-Medium.ttf +0 -0
  76. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/newsreader/Newsreader-Regular.ttf +0 -0
  77. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/newsreader/Newsreader-SemiBold.ttf +0 -0
  78. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/fonts/newsreader/OFL.txt +0 -0
  79. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/reference.py +0 -0
  80. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/swico.py +0 -0
  81. {quints-0.18.0 → quints-0.20.0}/src/quints/invoice/vatid.py +0 -0
  82. {quints-0.18.0 → quints-0.20.0}/src/quints/ledger.py +0 -0
  83. {quints-0.18.0 → quints-0.20.0}/src/quints/liability.py +0 -0
  84. {quints-0.18.0 → quints-0.20.0}/src/quints/match.py +0 -0
  85. {quints-0.18.0 → quints-0.20.0}/src/quints/payables.py +0 -0
  86. {quints-0.18.0 → quints-0.20.0}/src/quints/plugins/__init__.py +0 -0
  87. {quints-0.18.0 → quints-0.20.0}/src/quints/plugins/kmu.py +0 -0
  88. {quints-0.18.0 → quints-0.20.0}/src/quints/prices.py +0 -0
  89. {quints-0.18.0 → quints-0.20.0}/src/quints/receivables.py +0 -0
  90. {quints-0.18.0 → quints-0.20.0}/src/quints/settlement.py +0 -0
  91. {quints-0.18.0 → quints-0.20.0}/src/quints/ui.py +0 -0
  92. {quints-0.18.0 → quints-0.20.0}/src/quints/vat.py +0 -0
  93. {quints-0.18.0 → quints-0.20.0}/tests/fixtures/transactions.mt940 +0 -0
  94. {quints-0.18.0 → quints-0.20.0}/tests/test_cli_errors.py +0 -0
  95. {quints-0.18.0 → quints-0.20.0}/tests/test_closing.py +0 -0
  96. {quints-0.18.0 → quints-0.20.0}/tests/test_config.py +0 -0
  97. {quints-0.18.0 → quints-0.20.0}/tests/test_config_strict.py +0 -0
  98. {quints-0.18.0 → quints-0.20.0}/tests/test_docs.py +0 -0
  99. {quints-0.18.0 → quints-0.20.0}/tests/test_durable_writes.py +0 -0
  100. {quints-0.18.0 → quints-0.20.0}/tests/test_fava_ext.py +0 -0
  101. {quints-0.18.0 → quints-0.20.0}/tests/test_fx.py +0 -0
  102. {quints-0.18.0 → quints-0.20.0}/tests/test_importing.py +0 -0
  103. {quints-0.18.0 → quints-0.20.0}/tests/test_importing_stripe_invoices.py +0 -0
  104. {quints-0.18.0 → quints-0.20.0}/tests/test_inbox_match.py +0 -0
  105. {quints-0.18.0 → quints-0.20.0}/tests/test_kmu_plugin.py +0 -0
  106. {quints-0.18.0 → quints-0.20.0}/tests/test_ledger.py +0 -0
  107. {quints-0.18.0 → quints-0.20.0}/tests/test_loader_errors.py +0 -0
  108. {quints-0.18.0 → quints-0.20.0}/tests/test_money_defaults.py +0 -0
  109. {quints-0.18.0 → quints-0.20.0}/tests/test_mwst.py +0 -0
  110. {quints-0.18.0 → quints-0.20.0}/tests/test_payables.py +0 -0
  111. {quints-0.18.0 → quints-0.20.0}/tests/test_prices_ecosystem.py +0 -0
  112. {quints-0.18.0 → quints-0.20.0}/tests/test_prices_sync.py +0 -0
  113. {quints-0.18.0 → quints-0.20.0}/tests/test_receivables.py +0 -0
  114. {quints-0.18.0 → quints-0.20.0}/tests/test_saldo.py +0 -0
  115. {quints-0.18.0 → quints-0.20.0}/tests/test_settlement.py +0 -0
  116. {quints-0.18.0 → quints-0.20.0}/tests/test_statements_crosscheck.py +0 -0
  117. {quints-0.18.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.18.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
@@ -15,6 +15,14 @@ This project is a git repository; `quints init` committed the pristine
15
15
  scaffold. Work in reviewable steps: `git diff` before moving drafts into
16
16
  `books/`, commit once `quints check` passes — the history is the audit trail.
17
17
 
18
+ ## Confidential data
19
+
20
+ These are the company's books: its customers, suppliers, bank balances and
21
+ their documents, some of them personal data. Whatever you read here goes to
22
+ your model provider. Read what the task needs, never open `.env` or `.wise/`,
23
+ and never send the books to a service the company hasn't approved. Keep the
24
+ git remote private.
25
+
18
26
  ## Layout
19
27
 
20
28
  - `main.bean` — options, plugins, includes; the entry point every tool loads.
@@ -11,6 +11,10 @@
11
11
  kmu: "1170" ; Input VAT
12
12
  2026-01-01 open Liabilities:CH:GmbH:Payable:Trade
13
13
  kmu: "2000" ; Trade payables
14
+ 2026-01-01 open Liabilities:CH:GmbH:Advances:Domestic
15
+ kmu: "2030" ; Advances received
16
+ 2026-01-01 open Liabilities:CH:GmbH:Advances:Export
17
+ kmu: "2030" ; Advances received
14
18
  ; Fixed assets: `quints close depreciation --year <year>` prints the
15
19
  ; year's write-down from the metadata below, and `quints close check`
16
20
  ; verifies it was booked. Rates are the ESTV Merkblatt A/1995 maxima
@@ -36,6 +36,8 @@ reduced_marker = ":Reduced" # 2.6 % rate class → Ziffer 313
36
36
  lodging_marker = ":Lodging" # 3.8 % Beherbergung → Ziffer 343
37
37
  income_domestic = "Income:CH:GmbH:Consulting:External:Domestic"
38
38
  income_export = "Income:CH:GmbH:Consulting:External:Export"
39
+ advances_domestic = "Liabilities:CH:GmbH:Advances:Domestic" # pro forma payments, until invoiced
40
+ advances_export = "Liabilities:CH:GmbH:Advances:Export"
39
41
  fx_gain = "Income:CH:GmbH:FX:CurrencyGain"
40
42
  fx_loss = "Expenses:CH:GmbH:FX:CurrencyLoss"
41
43
  rounding_income = "Income:CH:GmbH:Rounding"
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "quints"
3
- version = "0.18.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",
@@ -245,23 +245,15 @@ def _problems(violations: list[ledger.Violation], *, err: bool = False) -> None:
245
245
  console.print(ui.violations_table(violations, "Problems in the books"))
246
246
 
247
247
 
248
- def _vat_chf(file: Path, totals: Totals, inv: Invoice) -> Decimal | None:
249
- """An invoice's VAT in CHF at its issue date, for the ledger draft — None
250
- when it is CHF already or the books hold no rate (the draft says so)."""
251
- from beancount.core.amount import Amount
252
-
253
- if inv.currency == "CHF" or not totals.vat_amount:
248
+ def _chf_rate(file: Path, inv: Invoice) -> Decimal | None:
249
+ """CHF per unit of a foreign invoice's currency on its issue date, for the
250
+ ledger draft's VAT — None when it is CHF already, a pro forma (owed at the
251
+ day received), or the books hold no rate (the draft says so)."""
252
+ if inv.currency == "CHF" or inv.proforma:
254
253
  return None
255
254
  entries, _ = ledger.load_entries(file) # its errors were listed by the cross-check
256
- try:
257
- chf = ledger.to_chf(
258
- Amount(totals.vat_amount, inv.currency),
259
- inv.issue_date,
260
- bc_prices.build_price_map(entries),
261
- )
262
- except ledger.RateUnavailable:
263
- return None
264
- return ledger.rappen(chf)
255
+ _, rate = ledger.rate(bc_prices.build_price_map(entries), inv.currency, inv.issue_date)
256
+ return rate
265
257
 
266
258
 
267
259
  def _require_ledger(file: Path) -> None:
@@ -844,10 +836,9 @@ def invoice(
844
836
  # an invoice from before registration (or after it ended) carries no VAT.
845
837
  registered = cfg.liable_on(inv.issue_date)
846
838
  if out is None:
847
- # File the PDF the way beancount documents are filed: under the income
848
- # account's folder, date-prefixed, next to the ledger's other evidence.
849
- account = cfg.income_export if inv.kind == "export" else cfg.income_domestic
850
- out = m.document_path(inv, account)
839
+ # File the PDF the way beancount documents are filed: under the folder
840
+ # of the account it books against, date-prefixed, next to the evidence.
841
+ out = m.document_path(inv, dr.filing_account(inv, cfg))
851
842
  path, totals, payload = r.render(inv, iss, out, vat_registered=registered)
852
843
  ref = ref_mod.payment_reference(inv, iss.account(inv.currency))
853
844
 
@@ -859,7 +850,9 @@ def invoice(
859
850
  if verify and file.exists():
860
851
  cc = v.cross_check(file, inv, totals)
861
852
  if not cc.found:
862
- ledger_draft = dr.build_draft(inv, totals, vat_chf=_vat_chf(file, totals, inv))
853
+ ledger_draft = dr.build_draft(
854
+ inv, totals, chf_rate=_chf_rate(file, inv), received=cc.received
855
+ )
863
856
  if not as_json:
864
857
  _print_cross_check(cc, inv, ledger_draft)
865
858
  elif verify and not as_json:
@@ -870,10 +863,13 @@ def invoice(
870
863
 
871
864
 
872
865
  def _qr_payload_ok(payload: str | None) -> bool | None:
873
- """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."""
874
868
  if not payload:
875
869
  return None
876
870
  lines = payload.splitlines()
871
+ if lines[:1] == ["BCD"]:
872
+ return lines[3:4] == ["SCT"]
877
873
  return lines[:1] == ["SPC"] and "EPD" in lines
878
874
 
879
875
 
@@ -892,6 +888,7 @@ def _invoice_payload(
892
888
  return {
893
889
  "number": inv.number,
894
890
  "kind": inv.kind,
891
+ "proforma": inv.proforma,
895
892
  "currency": inv.currency,
896
893
  "issue_date": inv.issue_date,
897
894
  "customer": inv.resolved_customer.name,
@@ -918,8 +915,9 @@ def _print_rendered(
918
915
  """What was written: the PDF, its reference, VAT status and QR payload."""
919
916
  from .invoice import model as m
920
917
 
918
+ kind = f"pro forma {inv.kind}" if inv.proforma else inv.kind
921
919
  ui.console.print(
922
- f"[ok]Wrote[/] {path} · {inv.kind} · {inv.currency} {m.money(totals.grand_total)}"
920
+ f"[ok]Wrote[/] {path} · {kind} · {inv.currency} {m.money(totals.amount_due)}"
923
921
  )
924
922
  ui.console.print(f"[muted]ref {ref.kind} {ref.formatted}[/]")
925
923
  if not registered:
@@ -927,8 +925,9 @@ def _print_rendered(
927
925
  f"[muted]not VAT-registered on {inv.issue_date}: no VAT charged or shown[/]"
928
926
  )
929
927
  if payload:
928
+ name, shape = ("EPC QR", "BCD…SCT") if payload.startswith("BCD") else ("QR-bill", "SPC…EPD")
930
929
  ui.console.print(
931
- f"[muted]QR-bill payload: {'SPC…EPD ✓' if qr_ok else 'CHECK!'} "
930
+ f"[muted]{name} payload: {f'{shape} ✓' if qr_ok else 'CHECK!'} "
932
931
  f"({len(payload.splitlines())} lines)[/]"
933
932
  )
934
933
 
@@ -938,7 +937,18 @@ def _print_cross_check(cc: CrossCheck, inv: Invoice, ledger_draft: str | None) -
938
937
  from .invoice import model as m
939
938
 
940
939
  _problems(cc.violations)
941
- if not cc.found:
940
+ for problem in cc.advance_problems:
941
+ ui.console.print(
942
+ f"[err]{problem}[/] — fix the invoice's `advances` or the receipt booking."
943
+ )
944
+ if not cc.found and inv.proforma:
945
+ ui.console.print(
946
+ f"[warn]No payment booked for pro forma {inv.number} yet[/] — when it arrives, "
947
+ f"book it with these legs into books/<year>.bean:\n"
948
+ )
949
+ print(ledger_draft)
950
+ print()
951
+ elif not cc.found:
942
952
  ui.console.print(
943
953
  f"[warn]No ledger txn for {inv.number}[/] — paste this draft "
944
954
  f"into books/{inv.issue_date.year}.bean:\n"
@@ -948,9 +958,16 @@ def _print_cross_check(cc: CrossCheck, inv: Invoice, ledger_draft: str | None) -
948
958
  elif cc.ok:
949
959
  if cc.ledger_total is None: # unreachable: found implies totals are set
950
960
  raise ValueError(f"cross-check for {inv.number} lost its ledger total")
951
- ui.console.print(
952
- f"[ok]Ledger match[/] ({cc.date}): {inv.currency} {m.money(cc.ledger_total)}"
953
- )
961
+ if inv.proforma and cc.invoice_total is not None and cc.ledger_total < cc.invoice_total:
962
+ ui.console.print(
963
+ f"[ok]Advance received[/] ({cc.date}): {inv.currency} "
964
+ f"{m.money(cc.ledger_total)} of {m.money(cc.invoice_total)}"
965
+ )
966
+ else:
967
+ what = "Advance received" if inv.proforma else "Ledger match"
968
+ ui.console.print(
969
+ f"[ok]{what}[/] ({cc.date}): {inv.currency} {m.money(cc.ledger_total)}"
970
+ )
954
971
  if not cc.date_ok:
955
972
  ui.console.print(f"[warn]booking date {cc.date} ≠ invoice date {inv.issue_date}[/]")
956
973
  else:
@@ -1546,9 +1563,29 @@ def statements(
1546
1563
  lang = lang or config_mod.get().report_language
1547
1564
  bilanz_report = kmu_mod.compute_bilanz(file, balance_date, date_from=date_from)
1548
1565
  erfolg_report = kmu_mod.compute_erfolg(file, date_from, balance_date)
1566
+ # The prior year's figures sit next to this year's (Art. 958d Abs. 2 OR).
1567
+ # An extended first year (`--from`) and a year with empty books before it
1568
+ # have none.
1569
+ # shortcut: the prior year is a calendar year, so after an extended first
1570
+ # year its column covers only that year's calendar part; add --prior-from if asked.
1571
+ prior = None
1572
+ if from_ is None:
1573
+ prior_bilanz = kmu_mod.compute_bilanz(
1574
+ file, f"{year - 1}-12-31", date_from=f"{year - 1}-01-01"
1575
+ )
1576
+ prior_erfolg = kmu_mod.compute_erfolg(file, f"{year - 1}-01-01", f"{year - 1}-12-31")
1577
+ if prior_bilanz.total_assets or prior_erfolg.result:
1578
+ prior = (prior_bilanz, prior_erfolg)
1549
1579
  out = out or Path(f"statements-{year}-{lang}.pdf")
1550
- path = report_pdf.render_pdf(bilanz_report, erfolg_report, lang, out)
1580
+ path = report_pdf.render_pdf(bilanz_report, erfolg_report, lang, out, prior=prior)
1551
1581
  typer.secho(f"Wrote {path}", fg="green")
1582
+ if prior is None and from_ is None:
1583
+ typer.secho(
1584
+ f"No figures for {year - 1} in the books, so the statements have no "
1585
+ "prior-year column (Art. 958d Abs. 2 OR). If the company existed then, "
1586
+ f"date the opening balances {year - 1}-12-31 instead of {year}-01-01.",
1587
+ fg="yellow",
1588
+ )
1552
1589
  if bilanz_report.violations:
1553
1590
  typer.secho("The statements list these problems in the books at the top:", fg="yellow")
1554
1591
  _problems(bilanz_report.violations)
@@ -243,6 +243,12 @@ class Config:
243
243
  rounding_income: str = "Income:CH:GmbH:Rounding"
244
244
  income_domestic: str = "Income:CH:GmbH:Consulting:External:Domestic"
245
245
  income_export: str = "Income:CH:GmbH:Consulting:External:Export"
246
+ # Customer advances (KMU 2030 Erhaltene Anzahlungen): a payment against a
247
+ # pro forma, held until the invoice credits it. The return counts it as
248
+ # turnover on receipt (Art. 40 Abs. 1 Bst. c MWSTG), so `mwst` routes these
249
+ # like the income account they mirror — the export one carries the marker.
250
+ advances_domestic: str = "Liabilities:CH:GmbH:Advances:Domestic"
251
+ advances_export: str = "Liabilities:CH:GmbH:Advances:Export"
246
252
  # Saldosteuersatz method only. The difference between the statutory VAT
247
253
  # invoiced and the SSS owed lands in `saldo_difference` at settlement;
248
254
  # Bezugsteuer is a cost, not a deduction, so it lands in
@@ -320,6 +326,19 @@ class Config:
320
326
  """Whether the entity is VAT-registered on ``day``."""
321
327
  return self.phase_at(day) is not None
322
328
 
329
+ @property
330
+ def advances(self) -> tuple[str, str]:
331
+ """The customer-advance accounts: held at the CHF received, turnover to `mwst`."""
332
+ return (self.advances_domestic, self.advances_export)
333
+
334
+ def advances_for(self, kind: str) -> str:
335
+ """The advances account of an invoice `kind` (domestic or export)."""
336
+ return self.advances_export if kind == "export" else self.advances_domestic
337
+
338
+ def mirrored_income(self, account: str) -> str:
339
+ """The income account an advances account stands in for until invoiced."""
340
+ return self.income_export if account == self.advances_export else self.income_domestic
341
+
323
342
  def for_period(self, d0: Date, d1: Date) -> tuple[Config, Date, Date]:
324
343
  """The config one return is computed under, and the liable stretch of it.
325
344
 
@@ -445,6 +464,8 @@ _ACCOUNT_KEYS = (
445
464
  "rounding_income",
446
465
  "income_domestic",
447
466
  "income_export",
467
+ "advances_domestic",
468
+ "advances_export",
448
469
  "saldo_difference",
449
470
  "bezugsteuer_expense",
450
471
  )
@@ -78,6 +78,8 @@ def compute(
78
78
  root = p.account.split(":", 1)[0]
79
79
  if cfg.entity_marker not in p.account or root not in ("Assets", "Liabilities"):
80
80
  continue
81
+ if p.account in cfg.advances:
82
+ continue # settled by the supply, not in money: stays at the rate received
81
83
  if p.units is None or p.units.currency == "CHF":
82
84
  continue
83
85
  inventories.setdefault(p.account, Inventory()).add_position(p)
@@ -201,6 +201,8 @@ def _cfg(answers: Answers) -> config.Config:
201
201
  rounding_income=_sub(base.rounding_income, c),
202
202
  income_domestic=_sub(base.income_domestic, c),
203
203
  income_export=_sub(base.income_export, c),
204
+ advances_domestic=_sub(base.advances_domestic, c),
205
+ advances_export=_sub(base.advances_export, c),
204
206
  saldo_difference=_sub(base.saldo_difference, c),
205
207
  bezugsteuer_expense=_sub(base.bezugsteuer_expense, c),
206
208
  saldo=tuple(config.SaldoRate(Decimal(spec) / 100) for spec in sorted(answers.saldo_rates)),
@@ -241,6 +243,8 @@ def _backbone(answers: Answers) -> list[_Account]:
241
243
  _Account(cfg.receivable, "1100"),
242
244
  _Account(cfg.input_vat, "1170", (oc,)),
243
245
  _Account(cfg.payable, "2000"),
246
+ _Account(cfg.advances_domestic, "2030"),
247
+ _Account(cfg.advances_export, "2030"),
244
248
  _Account(
245
249
  _sub(_FIXED_ASSETS, c),
246
250
  "1510",
@@ -816,6 +820,8 @@ def _quints_toml(answers: Answers) -> str:
816
820
  *_marker_lines(cfg),
817
821
  f'income_domestic = "{cfg.income_domestic}"',
818
822
  f'income_export = "{cfg.income_export}"',
823
+ f'advances_domestic = "{cfg.advances_domestic}" # pro forma payments, until invoiced',
824
+ f'advances_export = "{cfg.advances_export}"',
819
825
  *_saldo_account_lines(answers, cfg),
820
826
  f'fx_gain = "{cfg.fx_gain}"',
821
827
  f'fx_loss = "{cfg.fx_loss}"',
@@ -1145,6 +1151,14 @@ This project is a git repository; `quints init` committed the pristine
1145
1151
  scaffold. Work in reviewable steps: `git diff` before moving drafts into
1146
1152
  `books/`, commit once `quints check` passes — the history is the audit trail.
1147
1153
 
1154
+ ## Confidential data
1155
+
1156
+ These are the company's books: its customers, suppliers, bank balances and
1157
+ their documents, some of them personal data. Whatever you read here goes to
1158
+ your model provider. Read what the task needs, never open `.env` or `.wise/`,
1159
+ and never send the books to a service the company hasn't approved. Keep the
1160
+ git remote private.
1161
+
1148
1162
  ## Layout
1149
1163
 
1150
1164
  - `main.bean` — options, plugins, includes; the entry point every tool loads.
@@ -0,0 +1,151 @@
1
+ """Ready-to-paste Beancount draft for an invoice with no ledger entry yet."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from collections.abc import Mapping
6
+ from decimal import Decimal
7
+
8
+ from .. import config, ledger
9
+ from .model import Invoice, Totals, document_path, vat_included
10
+ from .verify import Received
11
+
12
+
13
+ def _quoted(value: str) -> str:
14
+ """A beancount string literal — free text from the customer must not be
15
+ able to break the draft out of its quotes."""
16
+ return '"' + value.replace("\\", "\\\\").replace('"', '\\"') + '"'
17
+
18
+
19
+ def filing_account(inv: Invoice, cfg: config.Config) -> str:
20
+ """The account the invoice books against, and its PDF is filed under: the
21
+ income account — or, for a pro forma, the customer advances it becomes."""
22
+ if inv.proforma:
23
+ return cfg.advances_for(inv.kind)
24
+ return cfg.income_export if inv.kind == "export" else cfg.income_domestic
25
+
26
+
27
+ def _vat_leg(vat: Decimal, ccy: str, chf_rate: Decimal | None, todo: str = "") -> str:
28
+ """The OutputVAT amount: CHF as the return is, priced ``@@`` in `ccy`."""
29
+ if ccy == "CHF":
30
+ return f"{-vat:>10.2f} {ccy}"
31
+ if chf_rate is not None:
32
+ return f"{-ledger.rappen(vat * chf_rate):>10.2f} CHF @@ {vat:.2f} {ccy}"
33
+ return f"{-vat:>10.2f} {ccy} ; TODO in CHF{todo}: quints vat convert"
34
+
35
+
36
+ def _lines(header: str, meta: list[str], legs: list[tuple[str, str, str]]) -> str:
37
+ width = max(len(a) for a, _, _ in legs) + 4
38
+ out = [header, *meta]
39
+ for account, amount, posting_meta in legs:
40
+ out.append(f" {account:<{width}}{amount}")
41
+ if posting_meta:
42
+ out.append(f" {posting_meta}")
43
+ return "\n".join(out)
44
+
45
+
46
+ def receipt_draft(inv: Invoice, totals: Totals, cfg: config.Config | None = None) -> str:
47
+ """The booking for a pro forma's payment, when it arrives.
48
+
49
+ Not income yet: the advance is a liability until the invoice credits it.
50
+ The return declares it on receipt all the same — with its VAT when
51
+ domestic (Art. 40 Abs. 1 Bst. c MWSTG), so the VAT is split out of the
52
+ gross received the way the invoice will credit it back (`vat_included`).
53
+ """
54
+ cfg = cfg or config.get()
55
+ ccy = inv.currency
56
+ gross = totals.amount_due
57
+ vat = vat_included(gross, totals.vat_rate)
58
+ doc = document_path(inv, filing_account(inv, cfg))
59
+ legs = [(filing_account(inv, cfg), f"{-(gross - vat):>10.2f} {ccy}", "")]
60
+ if vat:
61
+ legs.append((cfg.output_vat, _vat_leg(vat, ccy, None, " at the day received"), ""))
62
+ header = (
63
+ f"{inv.issue_date} * {_quoted(inv.resolved_customer.name)} "
64
+ f"{_quoted(f'Advance on pro forma {inv.number}')} ^{inv.number}"
65
+ " ; TODO the day it was received"
66
+ )
67
+ meta = [
68
+ f" proforma: {_quoted(inv.number)}",
69
+ f" document: {_quoted(doc.name)} ; TODO file the PDF under {doc.parent}/",
70
+ f" ; TODO the bank leg: {gross:.2f} {ccy} into the account it was paid to.",
71
+ ]
72
+ if vat:
73
+ meta.append(
74
+ " ; A different amount arrived? Split that: VAT = amount × rate / (100 + rate)."
75
+ )
76
+ return _lines(header, meta, legs)
77
+
78
+
79
+ def build_draft(
80
+ inv: Invoice,
81
+ totals: Totals,
82
+ cfg: config.Config | None = None,
83
+ chf_rate: Decimal | None = None,
84
+ received: Mapping[str, Received] | None = None,
85
+ ) -> str:
86
+ """A balanced receivable booking matching what `verify.cross_check` expects.
87
+
88
+ VAT is owed in CHF, so on a foreign-currency invoice the OutputVAT leg is
89
+ CHF at ``chf_rate`` (the issue date's), priced ``@@`` at the invoice's
90
+ VAT. Without a rate it stays in the invoice currency, marked to convert.
91
+
92
+ Credited advances are released as their receipts booked them
93
+ (``received``, from `verify.cross_check`): the VAT they declared is not
94
+ owed again, and a foreign advance leaves at the CHF it came in at — the
95
+ income it becomes is valued at that too, so the advances account clears
96
+ in CHF as well as in units. A pro forma missing from ``received`` is
97
+ released as the invoice credits it.
98
+ """
99
+ cfg = cfg or config.get()
100
+ if inv.proforma:
101
+ return receipt_draft(inv, totals, cfg)
102
+ customer = inv.resolved_customer
103
+ ccy = inv.currency
104
+ income = filing_account(inv, cfg)
105
+ advances = cfg.advances_for(inv.kind)
106
+ narration = f"{inv.supply.text(inv.locale)} invoiced"
107
+ doc = document_path(inv, income) # same name the rendered PDF is filed under
108
+
109
+ vat = totals.vat_amount
110
+ rest = totals.subtotal # the income not advanced, valued at the issue date
111
+ slices: list[tuple[str, str, str]] = []
112
+ released: list[tuple[str, str, str]] = []
113
+ for number in dict.fromkeys(a.proforma for a in inv.advances):
114
+ r = (received or {}).get(number) or _as_credited(inv, number, totals.vat_rate)
115
+ vat -= r.vat
116
+ # Posting metadata, not a second ^link: receivables trust a lone invoice link.
117
+ tag = f"proforma: {_quoted(number)}"
118
+ if ccy != "CHF" and r.net_chf is not None:
119
+ rest -= r.net
120
+ slices.append((income, f"{-r.net:>10.2f} {ccy} @@ {r.net_chf:.2f} CHF", ""))
121
+ released.append((advances, f"{r.net:>10.2f} {ccy} @@ {r.net_chf:.2f} CHF", tag))
122
+ elif ccy != "CHF":
123
+ todo = " ; TODO @@ the CHF it was received at"
124
+ released.append((advances, f"{r.net:>10.2f} {ccy}{todo}", tag))
125
+ else:
126
+ released.append((advances, f"{r.net:>10.2f} {ccy}", tag))
127
+
128
+ legs = [*([(income, f"{-rest:>10.2f} {ccy}", "")] if rest else []), *slices]
129
+ if totals.amount_due:
130
+ legs.append((cfg.receivable, f"{totals.amount_due:>10.2f} {ccy}", ""))
131
+ legs += released
132
+ if vat:
133
+ legs.append((cfg.output_vat, _vat_leg(vat, ccy, chf_rate), ""))
134
+ if totals.rounding:
135
+ legs.append((cfg.rounding_income, f"{-totals.rounding:>10.2f} {ccy}", ""))
136
+
137
+ meta = [f" invoice: {_quoted(inv.number)}"]
138
+ if inv.customer_reference:
139
+ # The payer quotes their own reference, not ours, when they ask about
140
+ # this invoice — so the ledger can be searched by it too.
141
+ meta.append(f" customer_reference: {_quoted(inv.customer_reference)}")
142
+ meta.append(f" document: {_quoted(doc.name)} ; TODO file the PDF under {doc.parent}/")
143
+ header = f"{inv.issue_date} * {_quoted(customer.name)} {_quoted(narration)} ^{inv.number}"
144
+ return _lines(header, meta, legs)
145
+
146
+
147
+ def _as_credited(inv: Invoice, number: str, rate: Decimal) -> Received:
148
+ """An advance not (yet) in the books, split the way its receipt would be."""
149
+ gross = sum((a.amount for a in inv.advances if a.proforma == number), Decimal("0"))
150
+ vat = vat_included(gross, rate)
151
+ return Received(net=gross - vat, vat=vat, net_chf=None)
@@ -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)
@@ -6,15 +6,20 @@ these keys, so a new language is accepted the moment it is defined here — no
6
6
  other file to touch; the matching CLDR locale, e.g. `es_ES`, gives Babel the
7
7
  number/date formatting for free).
8
8
 
9
- The legally load-bearing strings — `terms`, `export_note`, `reverse_charge` —
9
+ The legally load-bearing strings — `terms`, `export_note`, `reverse_charge`,
10
+ `proforma_note`, `advance_vat` —
10
11
  should be reviewed by a native/legal speaker before an entry ships.
11
- `terms` MUST keep the literal `{days}` placeholder (`render` calls `.format`)."""
12
+ `terms` MUST keep the literal `{days}` placeholder, `advance` its `{number}`
13
+ and `{date}`, and `advance_vat` its `{vat}` (`render` calls `.format`)."""
12
14
 
13
15
  LABELS = {
14
16
  "de": {
15
17
  "invoice": "Rechnung",
16
18
  "invoice_no": "Rechnungs-Nr.",
17
19
  "date": "Rechnungsdatum",
20
+ "due_date": "Zahlbar bis",
21
+ "customer_vat": "MWST-Nr. Kunde",
22
+ "amount": "Betrag",
18
23
  "supply": "Leistungsperiode",
19
24
  "your_reference": "Ihre Referenz",
20
25
  "pos": "Pos.",
@@ -30,15 +35,30 @@ LABELS = {
30
35
  "beneficiary": "Begünstigter",
31
36
  "bank": "Bank",
32
37
  "reference": "Referenz",
38
+ "scan_to_pay": "Mit der Banking-App scannen",
39
+ "qr_bill": "QR-Rechnung",
40
+ "made_with": "Erstellt mit quints",
33
41
  "terms": "Zahlbar innert {days} Tagen netto.",
34
42
  "export_note": "Nicht der schweizerischen MWST unterliegend: Ort der "
35
43
  "Leistung im Ausland (Art. 8 Abs. 1 MWSTG).",
36
44
  "reverse_charge": "Reverse Charge — die Steuer ist vom Leistungsempfänger abzurechnen.",
45
+ "proforma": "Proforma-Rechnung",
46
+ "proforma_no": "Proforma-Nr.",
47
+ "proforma_date": "Datum",
48
+ "amount_due": "Zahlbar",
49
+ "invoice_total": "Rechnungstotal",
50
+ "advance": "Anzahlung {number} vom {date}",
51
+ "advance_vat": "inkl. MWST {vat}",
52
+ "proforma_note": "Zahlungsaufforderung für eine Anzahlung. Die Rechnung folgt mit "
53
+ "der Leistung und rechnet diese Zahlung samt der darin enthaltenen MWST an.",
37
54
  },
38
55
  "en": {
39
56
  "invoice": "Invoice",
40
57
  "invoice_no": "Invoice no.",
41
58
  "date": "Invoice date",
59
+ "due_date": "Due date",
60
+ "customer_vat": "Customer VAT no.",
61
+ "amount": "Amount",
42
62
  "supply": "Service period",
43
63
  "your_reference": "Your reference",
44
64
  "pos": "No.",
@@ -54,15 +74,30 @@ LABELS = {
54
74
  "beneficiary": "Beneficiary",
55
75
  "bank": "Bank",
56
76
  "reference": "Reference",
77
+ "scan_to_pay": "Scan with your banking app",
78
+ "qr_bill": "QR-bill",
79
+ "made_with": "Made with quints",
57
80
  "terms": "Payable within {days} days net.",
58
81
  "export_note": "Not subject to Swiss VAT: place of supply abroad "
59
82
  "(Art. 8 para. 1 Swiss VAT Act).",
60
83
  "reverse_charge": "Reverse charge — VAT to be accounted for by the recipient.",
84
+ "proforma": "Pro forma invoice",
85
+ "proforma_no": "Pro forma no.",
86
+ "proforma_date": "Date",
87
+ "amount_due": "Amount due",
88
+ "invoice_total": "Invoice total",
89
+ "advance": "Advance {number} received {date}",
90
+ "advance_vat": "incl. VAT {vat}",
91
+ "proforma_note": "Request for an advance payment. The invoice follows with the "
92
+ "supply and credits this payment, including the VAT it contains.",
61
93
  },
62
94
  "es": {
63
95
  "invoice": "Factura",
64
96
  "invoice_no": "N.º de factura",
65
97
  "date": "Fecha de factura",
98
+ "due_date": "Vencimiento",
99
+ "customer_vat": "NIF-IVA del cliente",
100
+ "amount": "Importe",
66
101
  "supply": "Periodo de servicio",
67
102
  "your_reference": "Su referencia",
68
103
  "pos": "N.º",
@@ -78,11 +113,23 @@ LABELS = {
78
113
  "beneficiary": "Beneficiario",
79
114
  "bank": "Banco",
80
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",
81
119
  "terms": "A pagar en un plazo de {days} días netos.",
82
120
  "export_note": "No sujeto al IVA suizo: lugar de la prestación en el "
83
121
  "extranjero (art. 8 apdo. 1 de la Ley suiza del IVA).",
84
122
  "reverse_charge": "Inversión del sujeto pasivo — el IVA debe ser "
85
123
  "liquidado por el destinatario.",
124
+ "proforma": "Factura proforma",
125
+ "proforma_no": "N.º de proforma",
126
+ "proforma_date": "Fecha",
127
+ "amount_due": "Importe a pagar",
128
+ "invoice_total": "Total factura",
129
+ "advance": "Anticipo {number} recibido el {date}",
130
+ "advance_vat": "IVA incl. {vat}",
131
+ "proforma_note": "Solicitud de pago anticipado. La factura se emitirá con la "
132
+ "prestación y descontará este pago, incluido el IVA que contiene.",
86
133
  },
87
134
  }
88
135