From d2f13fe0a6cd036d1dcf19775619a39a2c9bc909 Mon Sep 17 00:00:00 2001 From: Anurag Mishra <32095923+Anurag810@users.noreply.github.com> Date: Tue, 13 Aug 2019 13:19:24 +0530 Subject: [PATCH] fix: query (#18709) --- .../doctype/payment_entry/payment_entry.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 8c2ea73b56..fc46132c1b 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -648,13 +648,18 @@ def get_orders_to_be_billed(posting_date, party_type, party, orders = [] if voucher_type: - ref_field = "base_grand_total" if party_account_currency == company_currency else "grand_total" + if party_account_currency == company_currency: + grand_total_field = "base_grand_total" + rounded_total_field = "base_rounded_total" + else: + grand_total_field = "grand_total" + rounded_total_field = "rounded_total" orders = frappe.db.sql(""" select name as voucher_no, - {ref_field} as invoice_amount, - ({ref_field} - advance_paid) as outstanding_amount, + if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) as invoice_amount, + (if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) - advance_paid) as outstanding_amount, transaction_date as posting_date from `tab{voucher_type}` @@ -663,13 +668,14 @@ def get_orders_to_be_billed(posting_date, party_type, party, and docstatus = 1 and company = %s and ifnull(status, "") != "Closed" - and {ref_field} > advance_paid + and if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) > advance_paid and abs(100 - per_billed) > 0.01 {condition} order by transaction_date, name """.format(**{ - "ref_field": ref_field, + "rounded_total_field": rounded_total_field, + "grand_total_field": grand_total_field, "voucher_type": voucher_type, "party_type": scrub(party_type), "condition": condition