Repository navigation
fix(fx): give the hand-reconcile loan note only when no real currency paid the loan, and stop dropped cash rows passing the loan gate - #463
Merged
Conversation
…'s principal hiding a debt change Follow-up to #460 (the #449 broker-loan gate and ledger), from the review of its exact diff. - A lot that carries returned loan principal now remembers which loan it came from. The default's "the sale pays its own loan" exception applies only when that loan is the one being repaid. Before, principal of a loan already repaid by a funding (L1) that repaid a second loan at the same rate (L2) took L2's debt change out of 1633/1637 and sent the user to reconcile by hand (fx_loan_repayment_manual) instead of the plain note. No figure moves, only the note. - extractCashFxEvents can now list the cash rows it leaves out (no ECB rate, an orphan withholding, a refund or reversal it cannot emit). The loan gate rejects a currency with any such row, and it reconciles the cash rows per day instead of per period, so two unseen rows on two days can no longer cancel. A withholding netted into its income that day still passes. - CLAUDE.md: a loan-funded debit has zero gain only when no commission is allocated to it, as docs/traza-fx.md says.
…d-reconcile note The previous fix counted returned loan principal outside 1633/1637 only when it repaid its own loan. When BBB's sale repaid L1 with L2's principal and AAA's sale then repaid L2 with L1's, no currency ever paid for either principal, yet the report gave the plain note and told the user to lower 1633 (0) by 100 €, while the other sale order gave fx_loan_repayment_manual on the same figures. Each buy's loan now counts how much of its principal is still borrowed (borrowedLeft): it drops when currency in 1633/1637 repays the loan, when a slice stops being the loan's on its own day (same-day sale, same-day cover, opening balance), and when the principal pays a debt as borrowed currency. Returned principal counts outside the boxes for its own loan, and for another loan up to that count, borrowed units first. OTHER and CHAIN keep the plain note; CROSS matches OWN in both sale orders. No figure changes, only the note.
Contributor
|
Caution Review failedThe pull request is closed.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #463 +/- ##
=======================================
Coverage 94.06% 94.07%
=======================================
Files 64 64
Lines 8347 8382 +35
Branches 2891 2904 +13
=======================================
+ Hits 7852 7885 +33
- Misses 407 409 +2
Partials 88 88
🚀 New features to boost your workflow:
|
GeiserX
added a commit
that referenced
this pull request
Nov 18, 2026
…concile by hand (#464) * fix(fx): stop counting loan principal as borrowed after it repaid another loan with a result The default kept a loan's borrowed-principal count (borrowedLeft) too high when its returned principal repaid another loan at a nonzero result: only a gain-0 row took the spent units out. A later pass-on of the paid-for rest then went outside 1633/1637, and the loan note said `_manual` with too small a boxGain (PASS: 35 instead of 55 of 75 EUR). Tax figures never changed. Every repayment now retires the borrowed units it spends from their loan, borrowed units first; only a gain-0 row still counts them outside the boxes. docs/casillas.md, docs/traza-fx.md and the #449 Hard Trace now say that a repayment with a result is always in 1633/1637, and that another loan's principal is outside only for the part of its loan your currency has not paid, also when it paid another part (PR #463 review). * docs(fx): say that a repayment with a result pays its loan even when borrowed principal pays it docs/casillas.md and docs/traza-fx.md told the user that a loan's principal stays borrowed until currency of their own pays the loan. The code counts a loan as paid by any repayment in 1633/1637, also a row with a result paid with another loan's borrowed principal (P2: L2's principal repays L1 with a 5 EUR result, then L1's principal repays L3 inside the boxes, the plain note with gain 75; only at gain 0, P2-ZERO, does L1 stay borrowed: `_manual`, boxGain 15 of 65). The docs now say that, CLAUDE.md #449 pins P2 and P2-ZERO, and the PASS-ZERO test no longer claims the same split as PASS (PR #463 review).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
CodeRabbit reviewed #460 after it shipped in v0.66.9. It found two ways the broker-loan model (#449) could go wrong, plus one wrong line in
CLAUDE.md.fx_loan_repayment_manual). In v0.66.9 that exception applied to any loan's dollars, so a loan already paid by a funding could still turn the plain note («lower 1633 by the gain») into the hand-reconcile one. A first fix narrowed it to "only its own loan". Our review then found the reverse case. Two loans, L1 for AAA and L2 for BBB. BBB is sold first and its dollars repay L1. AAA is sold next and its dollars repay L2. No real currency ever paid either loan and 1633 holds 0, yet the report told the user to lower 1633 by 100 €.CLAUDE.mdoverstated a rule. It said a loan-funded fee always has zero gain. That holds only when no commission is allocated to it, asdocs/traza-fx.mdalready says.Fix
extractCashFxEventstakes an optional collector and lists every cash row it drops. The gate rejects the currency on any dropped row and reconciles cash per day. A withholding netted into its own dividend that day still passes.CLAUDE.mdnow states the commission condition.What users see
boxGain.Left on purpose
Both cases fail safe, toward the hand-reconcile note or the untracked path:
CLAUDE.mddocuments it.dateTimeand different settle dates is rejected by the per-day gate.Checks
Follow-up to #460, from the CodeRabbit review of its exact diff on the fork mirror.