(fix)test case: loyalty program, course schedule and more
diff --git a/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.json b/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.json
index 2ad3bb5..5975198 100644
--- a/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.json
+++ b/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.json
@@ -344,12 +344,12 @@
  "hide_toolbar": 0, 
  "idx": 0, 
  "image_view": 0, 
- "in_create": 0, 
+ "in_create": 1, 
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2018-08-21 16:15:49.911384", 
+ "modified": "2018-08-29 16:05:22.810347", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Loyalty Point Entry", 
@@ -422,6 +422,5 @@
  "sort_order": "DESC", 
  "title_field": "customer", 
  "track_changes": 1, 
- "track_seen": 0, 
- "track_views": 0
+ "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.py b/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.py
index f0dd887..d65a7d8 100644
--- a/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.py
+++ b/erpnext/accounts/doctype/loyalty_point_entry/loyalty_point_entry.py
@@ -18,7 +18,7 @@
 		date = today()
 
 	return frappe.db.sql('''
-		select name, loyalty_points, expiry_date, loyalty_program_tier
+		select name, loyalty_points, expiry_date, loyalty_program_tier, sales_invoice
 		from `tabLoyalty Point Entry`
 		where customer=%s and loyalty_program=%s
 			and expiry_date>=%s and loyalty_points>0 and company=%s
diff --git a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py
index 99553b4..bf7a0bc 100644
--- a/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py
+++ b/erpnext/accounts/doctype/loyalty_program/test_loyalty_program.py
@@ -188,6 +188,9 @@
 
 def create_records():
 	# create a new loyalty Account
+	if frappe.db.exists("Account", "Loyalty - _TC"):
+		return
+
 	frappe.get_doc({
 		"doctype": "Account",
 		"account_name": "Loyalty",
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index 6ffa6fb..05b8300 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -101,7 +101,7 @@
    "no_copy": 1, 
    "oldfieldname": "naming_series", 
    "oldfieldtype": "Select", 
-   "options": "ACC-SINV-.YYYY.-", 
+   "options": "ACC-SINV-.YYYY.-\n", 
    "permlevel": 0, 
    "print_hide": 1, 
    "print_hide_if_no_value": 0, 
@@ -2575,6 +2575,7 @@
    "label": "Loyalty Amount", 
    "length": 0, 
    "no_copy": 1, 
+   "options": "Company:company:default_currency", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 1, 
@@ -2807,7 +2808,7 @@
    "label": "Apply Additional Discount On", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "\nGrand Total\nNet Total", 
+   "options": "\nGrand Total\nNet Total\n", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 1, 
@@ -4661,7 +4662,7 @@
    "label": "Status", 
    "length": 0, 
    "no_copy": 1, 
-   "options": "\nDraft\nReturn\nCredit Note Issued\nSubmitted\nPaid\nUnpaid\nOverdue\nCancelled", 
+   "options": "\nDraft\nReturn\nCredit Note Issued\nSubmitted\nPaid\nUnpaid\nOverdue\nCancelled\n", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 1, 
@@ -4833,7 +4834,7 @@
    "no_copy": 0, 
    "oldfieldname": "is_opening", 
    "oldfieldtype": "Select", 
-   "options": "No\nYes", 
+   "options": "No\nYes\n", 
    "permlevel": 0, 
    "print_hide": 1, 
    "print_hide_if_no_value": 0, 
@@ -4865,7 +4866,7 @@
    "label": "C-Form Applicable", 
    "length": 0, 
    "no_copy": 1, 
-   "options": "No\nYes", 
+   "options": "No\nYes\n", 
    "permlevel": 0, 
    "print_hide": 1, 
    "print_hide_if_no_value": 0, 
@@ -5480,7 +5481,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2018-08-21 14:44:47.783382", 
+ "modified": "2018-08-29 16:23:03.940415", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Sales Invoice", 
@@ -5574,6 +5575,5 @@
  "timeline_field": "customer", 
  "title_field": "title", 
  "track_changes": 1, 
- "track_seen": 1, 
- "track_views": 0
+ "track_seen": 1
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index d1ef3a6..fd77d4b 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -1035,6 +1035,8 @@
 
 		points_to_redeem = self.loyalty_points
 		for lp_entry in loyalty_point_entries:
+			if lp_entry.sales_invoice == self.name:
+				continue
 			available_points = lp_entry.loyalty_points - flt(redemption_details.get(lp_entry.name))
 			if available_points > points_to_redeem:
 				redeemed_points = points_to_redeem
diff --git a/erpnext/education/doctype/course_schedule/test_course_schedule.py b/erpnext/education/doctype/course_schedule/test_course_schedule.py
index 9ba6bd3..a901f1e 100644
--- a/erpnext/education/doctype/course_schedule/test_course_schedule.py
+++ b/erpnext/education/doctype/course_schedule/test_course_schedule.py
@@ -9,6 +9,7 @@
 import datetime
 from frappe.utils import today, to_timedelta
 from erpnext.education.utils import OverlapError
+from frappe.utils.make_random import get_random
 
 # test_records = frappe.get_test_records('Course Schedule')
 
@@ -17,14 +18,14 @@
 		cs1 = make_course_schedule_test_record(simulate= True)
 
 		cs2 = make_course_schedule_test_record(schedule_date=cs1.schedule_date, from_time= cs1.from_time, 
-			to_time= cs1.to_time, instructor="_Test Instructor 2", room="RM0002", do_not_save= 1)
+			to_time= cs1.to_time, instructor="_Test Instructor 2", room=frappe.get_all("Room")[1].name, do_not_save= 1)
 		self.assertRaises(OverlapError, cs2.save)
 
 	def test_instructor_conflict(self):
 		cs1 = make_course_schedule_test_record(simulate= True)
 		
 		cs2 = make_course_schedule_test_record(from_time= cs1.from_time, to_time= cs1.to_time, 
-			student_group="Course-TC101-2014-2015 (_Test Academic Term)", room="RM0002", do_not_save= 1)
+			student_group="Course-TC101-2014-2015 (_Test Academic Term)", room=frappe.get_all("Room")[1].name, do_not_save= 1)
 		self.assertRaises(OverlapError, cs2.save)
 
 	def test_room_conflict(self):
@@ -38,7 +39,7 @@
 		cs1 = make_course_schedule_test_record(simulate= True)
 		
 		make_course_schedule_test_record(from_time= cs1.from_time, to_time= cs1.to_time, 
-			student_group="Course-TC102-2014-2015 (_Test Academic Term)", instructor="_Test Instructor 2", room="RM0002")
+			student_group="Course-TC102-2014-2015 (_Test Academic Term)", instructor="_Test Instructor 2", room=frappe.get_all("Room")[1].name)
 
 def make_course_schedule_test_record(**args):
 	args = frappe._dict(args)
@@ -47,7 +48,7 @@
 	course_schedule.student_group = args.student_group or "Course-TC101-2014-2015 (_Test Academic Term)"
 	course_schedule.course = args.course or "TC101"
 	course_schedule.instructor = args.instructor or "_Test Instructor"
-	course_schedule.room = args.room or "RM0001"
+	course_schedule.room = args.room or frappe.get_all("Room")[0].name
 	
 	course_schedule.schedule_date = args.schedule_date or today()
 	course_schedule.from_time = args.from_time or to_timedelta("01:00:00")