Reconcile partial invoice payments without counting deposits as sales
Suppose one invoice for 100 units is paid in two instalments: 40 and 60. Counting each incoming payment as a new sale inflates sales volume. Instead, match receipts against the original invoice identifier and keep unidentified payments separate.
The following synthetic example uses Python's decimal arithmetic, which is preferable to binary floating-point for exact two-decimal examples.
Match payments to invoice IDs
from collections import defaultdict from decimal import Decimal
invoices = { " INV-100 " : Decimal ( " 100.00 " ), " INV-200 " : Decimal ( " 50.00 " )} payments = [ ( " INV-100 " , " 40.00 " ), ( " INV-100 " , " 60.00 " ), ( " INV-200 " , " 49.00 " ), ( " UNKNOWN " , " 10.00 " ), ]
received = defaultdict ( Decimal ) unmatched = [] for invoice_id , amount_text in payments : amount = Decimal ( amount_text ) if invoice_id not in invoices : unmatched .…