minor fix in deferred revenue booking
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index 53d0fda..bdf8349 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -1119,12 +1119,12 @@
 					select name, posting_date from `tabGL Entry` where company=%s and account=%s and
 					voucher_type=%s and voucher_no=%s and voucher_detail_no=%s
 					order by posting_date desc limit 1
-				''', (self.company, item.deferred_revenue_account, "Sales Invoice", self.name, item.name), as_dict=True)[0]
+				''', (self.company, item.deferred_revenue_account, "Sales Invoice", self.name, item.name), as_dict=True)
 
 				if not prev_gl_entry:
 					booking_start_date = item.service_start_date
 				else:
-					booking_start_date = getdate(add_days(prev_gl_entry.posting_date, 1))
+					booking_start_date = getdate(add_days(prev_gl_entry[0].posting_date, 1))
 
 			total_days = date_diff(item.service_end_date, item.service_start_date)
 			total_booking_days = date_diff(booking_end_date, booking_start_date) + 1
@@ -1141,12 +1141,14 @@
 					select sum(debit) as total_debit, sum(debit_in_account_currency) as total_debit_in_account_currency, voucher_detail_no
 					from `tabGL Entry` where company=%s and account=%s and voucher_type=%s and voucher_no=%s and voucher_detail_no=%s
 					group by voucher_detail_no
-				''', (self.company, item.deferred_revenue_account, "Sales Invoice", self.name, item.name), as_dict=True)[0]
-				base_amount = flt(item.base_net_amount - gl_entries_details.total_debit, item.precision("base_net_amount"))
+				''', (self.company, item.deferred_revenue_account, "Sales Invoice", self.name, item.name), as_dict=True)
+				already_booked_amount = gl_entries_details[0].total_debit if gl_entries_details else 0
+				base_amount = flt(item.base_net_amount - already_booked_amount, item.precision("base_net_amount"))
 				if account_currency==self.company_currency:
 					amount = base_amount
 				else:
-					amount = flt(item.net_amount - gl_entries_details.total_debit_in_account_currency, item.precision("net_amount"))
+					already_booked_amount_in_account_currency = gl_entries_details[0].total_debit_in_account_currency if gl_entries_details else 0
+					amount = flt(item.net_amount - already_booked_amount_in_account_currency, item.precision("net_amount"))
 
 			# GL Entry for crediting the amount in the income
 			gl_entries.append(