fix(reconcile): fill earliest month deficit first in multi-month allocations
All checks were successful
Deploy to K8s / deploy (push) Successful in 9s

Replace proportional split with a fill-first loop that allocates
min(remaining, deficit) to each matched month in user-supplied order,
where deficit = expected - already_paid. Prior transactions' contributions
are now properly accounted for, so a second payment on overlapping months
fills only what's still owed instead of splitting proportionally by total
expected. Surplus after all deficits are covered goes to the credit bucket.

Fixes: Matyáš Thér 200+550 showing 566/183 instead of 500/250.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-11 23:59:36 +02:00
parent aaa876e593
commit 8734089223
8 changed files with 336 additions and 109 deletions

View File

@@ -1,7 +1,7 @@
{
"case": "03_proportional_remainder",
"func": "scripts.match_payments.reconcile",
"captured_at": "2026-05-06",
"captured_at": "2026-05-11",
"input": {
"members": [
{
@@ -54,10 +54,10 @@
"original_expected": 750,
"attendance_count": 3,
"exception": null,
"paid": 324.3243243243243,
"paid": 750.0,
"transactions": [
{
"amount": 324.3243243243243,
"amount": 750.0,
"date": "2026-03-10",
"sender": "Member_d035d9f9",
"message": "",
@@ -70,10 +70,10 @@
"original_expected": 750,
"attendance_count": 2,
"exception": null,
"paid": 324.3243243243243,
"paid": 50.0,
"transactions": [
{
"amount": 324.3243243243243,
"amount": 50.0,
"date": "2026-03-10",
"sender": "Member_d035d9f9",
"message": "",
@@ -86,25 +86,17 @@
"original_expected": 350,
"attendance_count": 2,
"exception": null,
"paid": 151.35135135135135,
"transactions": [
{
"amount": 151.35135135135135,
"date": "2026-03-10",
"sender": "Member_d035d9f9",
"message": "",
"confidence": "auto"
}
]
"paid": 0,
"transactions": []
}
},
"other_transactions": [],
"total_balance": -1051
"total_balance": -1050
}
},
"unmatched": [],
"credits": {
"Member_d035d9f9": -1051
"Member_d035d9f9": -1050
}
}
}

View File

@@ -1,7 +1,7 @@
{
"case": "09_multiperson_multimonth",
"func": "scripts.match_payments.reconcile",
"captured_at": "2026-05-06",
"captured_at": "2026-05-11",
"input": {
"members": [
{
@@ -63,10 +63,10 @@
"original_expected": 750,
"attendance_count": 3,
"exception": null,
"paid": 500.0,
"paid": 750.0,
"transactions": [
{
"amount": 500.0,
"amount": 750.0,
"date": "2026-02-15",
"sender": "Member_d035d9f9",
"message": "",
@@ -79,10 +79,10 @@
"original_expected": 750,
"attendance_count": 2,
"exception": null,
"paid": 500.0,
"paid": 250.0,
"transactions": [
{
"amount": 500.0,
"amount": 250.0,
"date": "2026-02-15",
"sender": "Member_d035d9f9",
"message": "",
@@ -102,10 +102,10 @@
"original_expected": 750,
"attendance_count": 2,
"exception": null,
"paid": 681.8181818181819,
"paid": 750.0,
"transactions": [
{
"amount": 681.8181818181819,
"amount": 750.0,
"date": "2026-02-15",
"sender": "Member_d035d9f9",
"message": "",
@@ -118,10 +118,10 @@
"original_expected": 350,
"attendance_count": 2,
"exception": null,
"paid": 318.18181818181813,
"paid": 250.0,
"transactions": [
{
"amount": 318.18181818181813,
"amount": 250.0,
"date": "2026-02-15",
"sender": "Member_d035d9f9",
"message": "",
@@ -131,13 +131,13 @@
}
},
"other_transactions": [],
"total_balance": -101
"total_balance": -100
}
},
"unmatched": [],
"credits": {
"Member_d035d9f9": -500,
"Member_f4a93e46": -101
"Member_f4a93e46": -100
}
}
}