From fff56530c4e36257fed37da1dd7b165ba2b5cdd2 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Thu, 17 Aug 2017 14:47:25 +0530 Subject: [PATCH] [Fix] Due date not fetching on the payment entry against the invoices (#10419) --- erpnext/accounts/doctype/payment_entry/payment_entry.js | 1 + erpnext/accounts/utils.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 05986a0808..92a805f37d 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -499,6 +499,7 @@ frappe.ui.form.on('Payment Entry', { var c = frm.add_child("references"); c.reference_doctype = d.voucher_type; c.reference_name = d.voucher_no; + c.due_date = d.due_date c.total_amount = d.invoice_amount; c.outstanding_amount = d.outstanding_amount; if(!in_list(["Sales Order", "Purchase Order", "Expense Claim"], d.voucher_type)) { diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 6617802235..50530f5dc1 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -580,9 +580,15 @@ def get_outstanding_invoices(party_type, party, account, condition=None): dr_or_cr = "credit_in_account_currency - debit_in_account_currency" payment_dr_or_cr = "payment_gl_entry.debit_in_account_currency - payment_gl_entry.credit_in_account_currency" + invoice = 'Sales Invoice' if party_type == 'Customer' else 'Purchase Invoice' invoice_list = frappe.db.sql(""" select voucher_no, voucher_type, posting_date, ifnull(sum({dr_or_cr}), 0) as invoice_amount, + ( + 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 @@ -606,6 +612,7 @@ def get_outstanding_invoices(party_type, party, account, condition=None): having (invoice_amount - payment_amount) > 0.005 order by posting_date, name""".format( dr_or_cr = dr_or_cr, + invoice = invoice, payment_dr_or_cr = payment_dr_or_cr, condition = condition or "" ), { @@ -618,6 +625,7 @@ def get_outstanding_invoices(party_type, party, account, condition=None): 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),