Skip to content

Commit

Permalink
fix: from time and to time not updated in drag and drop action #29114
Browse files Browse the repository at this point in the history
fix: from time and to time not updated in drag and drop action
(cherry picked from commit 8b5827e)
  • Loading branch information
mohammedyusufshaikh authored and mergify-bot committed Jan 19, 2022
1 parent 6c45223 commit 02681d9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
4 changes: 2 additions & 2 deletions erpnext/education/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def get_course_schedule_events(start, end, filters=None):
conditions = get_event_conditions("Course Schedule", filters)

data = frappe.db.sql("""select name, course, color,
timestamp(schedule_date, from_time) as from_datetime,
timestamp(schedule_date, to_time) as to_datetime,
timestamp(schedule_date, from_time) as from_time,
timestamp(schedule_date, to_time) as to_time,
room, student_group, 0 as 'allDay'
from `tabCourse Schedule`
where ( schedule_date between %(start)s and %(end)s )
Expand Down
12 changes: 11 additions & 1 deletion erpnext/education/doctype/course_schedule/course_schedule.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# For license information, please see license.txt


from datetime import datetime

import frappe
from frappe import _
from frappe.model.document import Document
Expand Down Expand Up @@ -30,6 +32,14 @@ def validate_date(self):
if self.from_time > self.to_time:
frappe.throw(_("From Time cannot be greater than To Time."))

"""Handles specicfic case to update schedule date in calendar """
if isinstance(self.from_time, str):
try:
datetime_obj = datetime.strptime(self.from_time, '%Y-%m-%d %H:%M:%S')
self.schedule_date = datetime_obj
except ValueError:
pass

def validate_overlap(self):
"""Validates overlap for Student Group, Instructor, Room"""

Expand All @@ -47,4 +57,4 @@ def validate_overlap(self):
validate_overlap_for(self, "Assessment Plan", "student_group")

validate_overlap_for(self, "Assessment Plan", "room")
validate_overlap_for(self, "Assessment Plan", "supervisor", self.instructor)
validate_overlap_for(self, "Assessment Plan", "supervisor", self.instructor)
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
frappe.views.calendar["Course Schedule"] = {
field_map: {
// from_datetime and to_datetime don't exist as docfields but are used in onload
"start": "from_datetime",
"end": "to_datetime",
"start": "from_time",
"end": "to_time",
"id": "name",
"title": "course",
"allDay": "allDay"
"allDay": "allDay",
},
gantt: false,
order_by: "schedule_date",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import frappe
from frappe.utils import to_timedelta, today
from frappe.utils.data import add_to_date

from erpnext.education.utils import OverlapError

Expand Down Expand Up @@ -39,6 +40,11 @@ def test_no_conflict(self):
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=frappe.get_all("Room")[1].name)

def test_update_schedule_date(self):
doc = make_course_schedule_test_record(schedule_date= add_to_date(today(), days=1))
doc.schedule_date = add_to_date(doc.schedule_date, days=1)
doc.save()

def make_course_schedule_test_record(**args):
args = frappe._dict(args)

Expand Down

0 comments on commit 02681d9

Please sign in to comment.