fix failing tests
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py
index 4913fe1..6901c8e 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.py
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py
@@ -769,14 +769,18 @@
 	references = get_outstanding_reference_documents(args=args)
 
 	for reference in references:
-		pe.append("references", {
-			'reference_doctype': reference.voucher_type,
-			'reference_name': reference.voucher_no,
-			'due_date': reference.due_date,
-			'total_amount': reference.invoice_amount,
-			'outstanding_amount': reference.outstanding_amount,
-			'allocated_amount': reference.outstanding_amount
-		})
+		if reference.voucher_no == dn:
+			allocated_amount = min(paid_amount, reference.outstanding_amount)
+			pe.append("references", {
+				'reference_doctype': reference.voucher_type,
+				'reference_name': reference.voucher_no,
+				'due_date': reference.due_date,
+				'total_amount': reference.invoice_amount,
+				'outstanding_amount': reference.outstanding_amount,
+				'allocated_amount': reference.outstanding_amount
+			})
+			if paid_amount:
+				paid_amount -= allocated_amount
 
 	pe.setup_party_account_field()
 	pe.set_missing_values()
@@ -785,6 +789,7 @@
 		pe.set_amounts()
 	return pe
 
+
 def get_paid_amount(dt, dn, party_type, party, account, due_date):
 	if party_type=="Customer":
 		dr_or_cr = "credit_in_account_currency - debit_in_account_currency"