From 90f9f9d3d8b5545f9145fea570aa3941e8c745bb Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Sun, 30 Sep 2018 21:12:50 +0530 Subject: [PATCH] Code optimization for deferred revenue (#15527) --- erpnext/accounts/deferred_revenue.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/deferred_revenue.py b/erpnext/accounts/deferred_revenue.py index 61fc211aa4c..5e5c6e594e4 100644 --- a/erpnext/accounts/deferred_revenue.py +++ b/erpnext/accounts/deferred_revenue.py @@ -35,8 +35,8 @@ def validate_service_stop_date(doc): def convert_deferred_expense_to_expense(start_date=None, end_date=None): # check for the purchase invoice for which GL entries has to be done invoices = frappe.db.sql_list(''' - select parent from `tabPurchase Invoice Item` where service_start_date<=%s and service_end_date>=%s - and enable_deferred_expense = 1 and docstatus = 1 + select distinct parent from `tabPurchase Invoice Item` where service_start_date<=%s and service_end_date>=%s + and enable_deferred_expense = 1 and docstatus = 1 and ifnull(amount, 0) > 0 ''', (end_date or today(), start_date or add_months(today(), -1))) # For each invoice, book deferred expense @@ -47,8 +47,8 @@ def convert_deferred_expense_to_expense(start_date=None, end_date=None): def convert_deferred_revenue_to_income(start_date=None, end_date=None): # check for the sales invoice for which GL entries has to be done invoices = frappe.db.sql_list(''' - select parent from `tabSales Invoice Item` where service_start_date<=%s and service_end_date>=%s - and enable_deferred_revenue = 1 and docstatus = 1 + select distinct parent from `tabSales Invoice Item` where service_start_date<=%s and service_end_date>=%s + and enable_deferred_revenue = 1 and docstatus = 1 and ifnull(amount, 0) > 0 ''', (end_date or today(), start_date or add_months(today(), -1))) # For each invoice, book deferred revenue