Menu

Reconcile partial invoice payments without counting deposits as sales
📰

Reconcile partial invoice payments without counting deposits as sales

DEV Community: python·SUAD CUMA·10 days ago
#yjzSATZd
#devtopython#devto#dev#payments#decimal
Reading 0:00
15s threshold

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 .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.