Skip to content

fix(payables): ignore fava's ^dok-<date> links when keying bills - #14

Merged
borgoat merged 1 commit into
mainfrom
fix/payables-fava-dok-links
Oct 8, 2026
Merged

borgoat merged 1 commit into
mainfrom
fix/payables-fava-dok-links

Conversation

@borgoat

@borgoat borgoat commented Oct 8, 2026 •

Copy link
Copy Markdown
Member

Problem

fava.plugins.link_documents, which quints init scaffolds into main.bean, adds ^dok-<date> to every transaction with a document:. Bills carry it and payments don't. payables.bill_id took a transaction's only link as the bill id, so each bill split from its payment:

  • When dok- was the only link, it became the bill's key. The payment has no link and fell back to <payee> · <amount>, so the two never matched.
  • When the bill also had a real supplier link, the two links pushed the bill onto the fallback key, while the payment was keyed by the real link.

On a real ledger, quints payables showed every bill as open plus a negative row for each payment, even though Payable:Trade netted to 0.

Fix

  • payables.bill_id ignores links matching ^dok-\d{4}-\d{2}-\d{2}$. Every caller goes through it (_key_for, booked_bill, compute_from_entries, match.bill_reference_index), so one guard covers them all. Receivables were already unaffected because _INVOICE_ID rejects dok-.
  • importing.match_payables: when a payment draft is matched to a bill keyed by the payee/amount fallback, the key is set only as bill: metadata, not as a ^link. A key like Google · 24.13 isn't a valid beancount link, and this fix makes fallback-keyed bills common.

Test

test_fava_document_links_are_not_bill_ids in test_payables.py covers both shapes (lone dok- link, and dok- next to a real link). It fails without the fix and passes with it.

Full suite: 351 passed, 1 skipped. ruff check and ruff format are clean. Against a real ledger, quints payables now reports "Nothing open".

🤖 Generated with Claude Code

https://claude.ai/code/session_01Ji4UEwyzrv6U1Qf531NFyo

`fava.plugins.link_documents`, which `quints init` scaffolds into
main.bean, adds `^dok-<date>` to every transaction with a `document:`.
Bills get it and payments don't, and `payables.bill_id` took a
transaction's only link as the bill id, so each bill split from its
payment:

- with `dok-` as the only link, it became the bill's key while the
  payment, linkless, fell back to `<payee> · <amount>`;
- with a real supplier link next to it, the two links pushed the bill
  onto the fallback key while the payment was keyed by the real link.

On a real ledger `quints payables` listed every bill as open plus a
negative row for each payment, though Payable:Trade netted to 0.

`bill_id` now ignores links matching `^dok-\d{4}-\d{2}-\d{2}$`. Every
caller goes through it (`_key_for`, `booked_bill`, `compute_from_entries`,
`match.bill_reference_index`). Receivables were already unaffected:
`_INVOICE_ID` rejects `dok-`.

In importing.py, a payment draft matched to a bill keyed by the
payee/amount fallback now carries the key only as `bill:` metadata, not
as a `^link`. `Google · 24.13` is not a valid beancount link, and fallback
keys are now common.

Claude-Session: https://claude.ai/code/session_01Ji4UEwyzrv6U1Qf531NFyo
@borgoat
borgoat merged commit c0d8f34 into main Oct 8, 2026
8 checks passed
@borgoat
borgoat deleted the fix/payables-fava-dok-links branch October 8, 2026 16:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant