From b8471dd753c9c94e83304e50b5a08f8386c7b227 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Wed, 3 May 2023 20:55:49 +0530 Subject: [PATCH] feat: paid classes and seat count --- .../doctype/class_student_detail/__init__.py | 0 .../class_student_detail.js | 8 +++ .../class_student_detail.json | 51 +++++++++++++++++++ .../class_student_detail.py | 9 ++++ .../test_class_student_detail.py | 9 ++++ lms/lms/doctype/lms_class/lms_class.json | 15 +++++- lms/www/classes/index.html | 23 +++++++-- lms/www/classes/index.py | 13 ++++- 8 files changed, 120 insertions(+), 8 deletions(-) create mode 100644 lms/lms/doctype/class_student_detail/__init__.py create mode 100644 lms/lms/doctype/class_student_detail/class_student_detail.js create mode 100644 lms/lms/doctype/class_student_detail/class_student_detail.json create mode 100644 lms/lms/doctype/class_student_detail/class_student_detail.py create mode 100644 lms/lms/doctype/class_student_detail/test_class_student_detail.py diff --git a/lms/lms/doctype/class_student_detail/__init__.py b/lms/lms/doctype/class_student_detail/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/lms/lms/doctype/class_student_detail/class_student_detail.js b/lms/lms/doctype/class_student_detail/class_student_detail.js new file mode 100644 index 00000000..5ee5c29a --- /dev/null +++ b/lms/lms/doctype/class_student_detail/class_student_detail.js @@ -0,0 +1,8 @@ +// Copyright (c) 2023, Frappe and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("Class Student Detail", { +// refresh(frm) { + +// }, +// }); diff --git a/lms/lms/doctype/class_student_detail/class_student_detail.json b/lms/lms/doctype/class_student_detail/class_student_detail.json new file mode 100644 index 00000000..039d8d8f --- /dev/null +++ b/lms/lms/doctype/class_student_detail/class_student_detail.json @@ -0,0 +1,51 @@ +{ + "actions": [], + "allow_rename": 1, + "creation": "2023-05-03 20:52:46.950991", + "default_view": "List", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "user", + "full_name" + ], + "fields": [ + { + "fieldname": "user", + "fieldtype": "Link", + "label": "User", + "options": "User" + }, + { + "fieldname": "full_name", + "fieldtype": "Data", + "label": "Full Name" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2023-05-03 20:52:46.950991", + "modified_by": "Administrator", + "module": "LMS", + "name": "Class Student Detail", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [], + "track_changes": 1 +} \ No newline at end of file diff --git a/lms/lms/doctype/class_student_detail/class_student_detail.py b/lms/lms/doctype/class_student_detail/class_student_detail.py new file mode 100644 index 00000000..86dd6138 --- /dev/null +++ b/lms/lms/doctype/class_student_detail/class_student_detail.py @@ -0,0 +1,9 @@ +# Copyright (c) 2023, Frappe and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + + +class ClassStudentDetail(Document): + pass diff --git a/lms/lms/doctype/class_student_detail/test_class_student_detail.py b/lms/lms/doctype/class_student_detail/test_class_student_detail.py new file mode 100644 index 00000000..bbdcb88f --- /dev/null +++ b/lms/lms/doctype/class_student_detail/test_class_student_detail.py @@ -0,0 +1,9 @@ +# Copyright (c) 2023, Frappe and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestClassStudentDetail(FrappeTestCase): + pass diff --git a/lms/lms/doctype/lms_class/lms_class.json b/lms/lms/doctype/lms_class/lms_class.json index a2a51330..ffcf5c31 100644 --- a/lms/lms/doctype/lms_class/lms_class.json +++ b/lms/lms/doctype/lms_class/lms_class.json @@ -11,7 +11,9 @@ "title", "start_date", "end_date", + "paid_class", "column_break_4", + "seat_count", "description", "section_break_6", "students", @@ -71,11 +73,22 @@ "fieldtype": "Code", "label": "Custom Component", "options": "HTML" + }, + { + "default": "0", + "fieldname": "paid_class", + "fieldtype": "Check", + "label": "Paid Class" + }, + { + "fieldname": "seat_count", + "fieldtype": "Int", + "label": "Seat Count" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-03-02 22:47:13.139289", + "modified": "2023-05-03 17:52:28.226169", "modified_by": "Administrator", "module": "LMS", "name": "LMS Class", diff --git a/lms/www/classes/index.html b/lms/www/classes/index.html index 8ffe6c23..c8438ac6 100644 --- a/lms/www/classes/index.html +++ b/lms/www/classes/index.html @@ -68,11 +68,7 @@
-
- {{ class.title }} -
- -
+
{% if course_count %} {{ course_count }} {{ _("Courses") }} @@ -84,6 +80,16 @@ {{ student_count }} {{ _("Students") }} {% endif %} + + {% if class.seats_left %} + + {{ class.seats_left }} {{ _("seats left") }} + + {% endif %} +
+ +
+ {{ class.title }}
@@ -97,6 +103,13 @@ {{ frappe.utils.format_date(class.end_date, "long") }}
+ + {% if class.paid_class and class.start_date > frappe.utils.getdate() %} + + {{ _("Register") }} + + {% endif %} +
{% endfor %} diff --git a/lms/www/classes/index.py b/lms/www/classes/index.py index c97d81b5..58e7510d 100644 --- a/lms/www/classes/index.py +++ b/lms/www/classes/index.py @@ -8,13 +8,22 @@ def get_context(context): context.is_moderator = has_course_moderator_role() classes = frappe.get_all( "LMS Class", - fields=["name", "title", "start_date", "end_date"], + fields=["name", "title", "start_date", "end_date", "paid_class", "seat_count"], ) + past_classes, upcoming_classes = [], [] for class_ in classes: - if getdate(class_.end_date) < getdate(): + if class_.seat_count: + filled_seats = frappe.db.count( + "Class Student", + filters={"parent": class_.name}, + ) + class_.seats_left = class_.seat_count - filled_seats + + if getdate(class_.start_date) < getdate(): past_classes.append(class_) else: upcoming_classes.append(class_) + context.past_classes = past_classes context.upcoming_classes = upcoming_classes