From 28f9b0a9ab69bc504c10cad1cbe725a168a32e25 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 29 Aug 2018 17:05:11 +0530 Subject: [PATCH] (fix)test case: loyalty program, course schedule and more --- .../loyalty_point_entry/loyalty_point_entry.json | 7 +++---- .../loyalty_point_entry/loyalty_point_entry.py | 2 +- .../loyalty_program/test_loyalty_program.py | 3 +++ .../doctype/sales_invoice/sales_invoice.json | 16 ++++++++-------- .../doctype/sales_invoice/sales_invoice.py | 2 ++ .../course_schedule/test_course_schedule.py | 9 +++++---- 6 files changed, 22 insertions(+), 17 deletions(-) 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 2ad3bb57bf..597519858a 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 f0dd887770..d65a7d88e6 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 @@ def get_loyalty_point_entries(customer, loyalty_program, company, expiry_date=No 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 99553b4db1..bf7a0bcfa4 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_sales_invoice_record(qty=1): 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 6ffa6fb743..05b83005ad 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 d1ef3a6999..fd77d4b47e 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1035,6 +1035,8 @@ class SalesInvoice(SellingController): 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 9ba6bd3e4b..a901f1e467 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 unittest 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 @@ class TestCourseSchedule(unittest.TestCase): 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 @@ class TestCourseSchedule(unittest.TestCase): 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 @@ def make_course_schedule_test_record(**args): 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")