Code optimization for deferred revenue (#15527)
diff --git a/erpnext/accounts/deferred_revenue.py b/erpnext/accounts/deferred_revenue.py
index 61fc211..5e5c6e5 100644
--- a/erpnext/accounts/deferred_revenue.py
+++ b/erpnext/accounts/deferred_revenue.py
@@ -35,8 +35,8 @@
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_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