fix bug: can't make PE for invoice with multi due date
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 6d6aced..6a81788 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -569,11 +569,12 @@
 	# Amount should be credited
 	return flt(stock_rbnb) + flt(sys_bal)
 
+
 def get_outstanding_invoices(party_type, party, account, condition=None):
 	outstanding_invoices = []
 	precision = frappe.get_precision("Sales Invoice", "outstanding_amount")
 
-	if party_type=="Customer":
+	if party_type == "Customer":
 		dr_or_cr = "debit_in_account_currency - credit_in_account_currency"
 		payment_dr_or_cr = "payment_gl_entry.credit_in_account_currency - payment_gl_entry.debit_in_account_currency"
 	else:
@@ -585,11 +586,6 @@
 		select
 			voucher_no,	voucher_type, posting_date, ifnull(sum({dr_or_cr}), 0) as invoice_amount, due_date,
 			(
-				case when (voucher_type = 'Sales Invoice' or voucher_type = 'Purchase Invoice')
-					then (select due_date from `tab{invoice}` where name = voucher_no)
-				else posting_date end
-			) as due_date,
-			(
 				select ifnull(sum({payment_dr_or_cr}), 0)
 				from `tabGL Entry` payment_gl_entry
 				where payment_gl_entry.against_voucher_type = invoice_gl_entry.voucher_type
@@ -612,10 +608,10 @@
 		group by voucher_type, voucher_no, due_date
 		having (invoice_amount - payment_amount) > 0.005
 		order by posting_date, name, due_date""".format(
-			dr_or_cr = dr_or_cr,
-			invoice = invoice,
-			payment_dr_or_cr = payment_dr_or_cr,
-			condition = condition or ""
+			dr_or_cr=dr_or_cr,
+			invoice=invoice,
+			payment_dr_or_cr=payment_dr_or_cr,
+			condition=condition or ""
 		), {
 			"party_type": party_type,
 			"party": party,
@@ -623,18 +619,24 @@
 		}, as_dict=True)
 
 	for d in invoice_list:
-		due_date = d.due_date or (frappe.db.get_value(d.voucher_type, d.voucher_no,
-			"posting_date" if party_type=="Employee" else "due_date"))
-		outstanding_invoices.append(frappe._dict({
-			'voucher_no': d.voucher_no,
-			'voucher_type': d.voucher_type,
-			'due_date': d.due_date,
-			'posting_date': d.posting_date,
-			'invoice_amount': flt(d.invoice_amount),
-			'payment_amount': flt(d.payment_amount),
-			'outstanding_amount': flt(d.invoice_amount - d.payment_amount, precision),
-			'due_date': due_date
-		}))
+		due_date = d.due_date or (
+			frappe.db.get_value(
+				d.voucher_type, d.voucher_no,
+				"posting_date" if party_type == "Employee" else "due_date"
+			)
+		)
+
+		outstanding_invoices.append(
+			frappe._dict({
+				'voucher_no': d.voucher_no,
+				'voucher_type': d.voucher_type,
+				'posting_date': d.posting_date,
+				'invoice_amount': flt(d.invoice_amount),
+				'payment_amount': flt(d.payment_amount),
+				'outstanding_amount': flt(d.invoice_amount - d.payment_amount, precision),
+				'due_date': due_date
+			})
+		)
 
 	outstanding_invoices = sorted(outstanding_invoices, key=lambda k: k['due_date'] or getdate(nowdate()))