From 243277012faa390ee7ec01a5ea6f7db4ccce6bcc Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 26 Oct 2023 17:51:43 +0530 Subject: [PATCH 1/3] feat: batch source --- lms/install.py | 23 +++++-- .../doctype/batch_student/batch_student.json | 17 +++-- lms/lms/doctype/lms_payment/lms_payment.json | 9 ++- lms/lms/doctype/lms_source/__init__.py | 0 lms/lms/doctype/lms_source/lms_source.js | 8 +++ lms/lms/doctype/lms_source/lms_source.json | 69 +++++++++++++++++++ lms/lms/doctype/lms_source/lms_source.py | 9 +++ lms/lms/doctype/lms_source/test_lms_source.py | 9 +++ lms/lms/utils.py | 10 +-- lms/patches.txt | 3 +- lms/patches/v1_0/create_batch_source.py | 5 ++ lms/www/billing/billing.js | 13 +++- 12 files changed, 156 insertions(+), 19 deletions(-) create mode 100644 lms/lms/doctype/lms_source/__init__.py create mode 100644 lms/lms/doctype/lms_source/lms_source.js create mode 100644 lms/lms/doctype/lms_source/lms_source.json create mode 100644 lms/lms/doctype/lms_source/lms_source.py create mode 100644 lms/lms/doctype/lms_source/test_lms_source.py create mode 100644 lms/patches/v1_0/create_batch_source.py diff --git a/lms/install.py b/lms/install.py index 459d2c387..e77cad23c 100644 --- a/lms/install.py +++ b/lms/install.py @@ -4,11 +4,11 @@ def after_install(): add_pages_to_nav() + create_batch_source() def after_sync(): create_lms_roles() - set_default_home() set_default_certificate_print_format() add_all_roles_to("Administrator") @@ -64,10 +64,6 @@ def delete_lms_roles(): frappe.db.delete("Role", role) -def set_default_home(): - frappe.db.set_single_value("Portal Settings", "default_portal_home", "/courses") - - def create_course_creator_role(): if not frappe.db.exists("Role", "Course Creator"): role = frappe.get_doc( @@ -182,3 +178,20 @@ def delete_custom_fields(): for field in fields: frappe.db.delete("Custom Field", {"fieldname": field}) + + +def create_batch_source(): + sources = [ + "Newsletter", + "LinkedIn", + "Twitter", + "Website", + "Friend/Colleague/Connection", + "Google Search", + ] + + for source in sources: + if not frappe.db.exists("LMS Batch Source", source): + doc = frappe.new_doc("LMS Batch Source") + doc.source = source + doc.save() diff --git a/lms/lms/doctype/batch_student/batch_student.json b/lms/lms/doctype/batch_student/batch_student.json index 313c79c40..2fa00921f 100644 --- a/lms/lms/doctype/batch_student/batch_student.json +++ b/lms/lms/doctype/batch_student/batch_student.json @@ -9,11 +9,12 @@ "field_order": [ "student_details_section", "student", - "payment", - "confirmation_email_sent", - "column_break_oduu", "student_name", - "username" + "username", + "column_break_oduu", + "payment", + "source", + "confirmation_email_sent" ], "fields": [ { @@ -59,12 +60,18 @@ "fieldname": "confirmation_email_sent", "fieldtype": "Check", "label": "Confirmation Email Sent" + }, + { + "fieldname": "source", + "fieldtype": "Link", + "label": "Source", + "options": "LMS Source" } ], "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2023-10-09 17:09:50.481794", + "modified": "2023-10-26 16:52:04.266693", "modified_by": "Administrator", "module": "LMS", "name": "Batch Student", diff --git a/lms/lms/doctype/lms_payment/lms_payment.json b/lms/lms/doctype/lms_payment/lms_payment.json index c0019aef7..82fb9388a 100644 --- a/lms/lms/doctype/lms_payment/lms_payment.json +++ b/lms/lms/doctype/lms_payment/lms_payment.json @@ -10,6 +10,7 @@ "field_order": [ "payment_for_document_type", "member", + "source", "column_break_rqkd", "payment_for_document", "billing_name", @@ -129,11 +130,17 @@ "fieldtype": "Dynamic Link", "label": "Payment for Document", "options": "payment_for_document_type" + }, + { + "fieldname": "source", + "fieldtype": "Link", + "label": "Source", + "options": "LMS Source" } ], "index_web_pages_for_search": 1, "links": [], - "modified": "2023-10-17 23:17:50.334975", + "modified": "2023-10-26 16:54:12.408274", "modified_by": "Administrator", "module": "LMS", "name": "LMS Payment", diff --git a/lms/lms/doctype/lms_source/__init__.py b/lms/lms/doctype/lms_source/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/lms/lms/doctype/lms_source/lms_source.js b/lms/lms/doctype/lms_source/lms_source.js new file mode 100644 index 000000000..e3c820015 --- /dev/null +++ b/lms/lms/doctype/lms_source/lms_source.js @@ -0,0 +1,8 @@ +// Copyright (c) 2023, Frappe and contributors +// For license information, please see license.txt + +// frappe.ui.form.on("LMS Source", { +// refresh(frm) { + +// }, +// }); diff --git a/lms/lms/doctype/lms_source/lms_source.json b/lms/lms/doctype/lms_source/lms_source.json new file mode 100644 index 000000000..a1361696b --- /dev/null +++ b/lms/lms/doctype/lms_source/lms_source.json @@ -0,0 +1,69 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "field:source", + "creation": "2023-10-26 16:28:53.932278", + "default_view": "List", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "source" + ], + "fields": [ + { + "fieldname": "source", + "fieldtype": "Data", + "label": "Source", + "unique": 1 + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2023-10-26 17:25:09.144367", + "modified_by": "Administrator", + "module": "LMS", + "name": "LMS Source", + "naming_rule": "By fieldname", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + }, + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "Moderator", + "share": 1, + "write": 1 + }, + { + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "LMS Student", + "select": 1, + "share": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC", + "states": [], + "title_field": "source" +} \ No newline at end of file diff --git a/lms/lms/doctype/lms_source/lms_source.py b/lms/lms/doctype/lms_source/lms_source.py new file mode 100644 index 000000000..cf881d0d6 --- /dev/null +++ b/lms/lms/doctype/lms_source/lms_source.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 LMSSource(Document): + pass diff --git a/lms/lms/doctype/lms_source/test_lms_source.py b/lms/lms/doctype/lms_source/test_lms_source.py new file mode 100644 index 000000000..99b7e97f9 --- /dev/null +++ b/lms/lms/doctype/lms_source/test_lms_source.py @@ -0,0 +1,9 @@ +# Copyright (c) 2023, Frappe and Contributors +# See license.txt + +# import frappe +from frappe.tests.utils import FrappeTestCase + + +class TestLMSSource(FrappeTestCase): + pass diff --git a/lms/lms/utils.py b/lms/lms/utils.py index b41af0dde..38fc5933b 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -898,7 +898,7 @@ def check_multicurrency(amount, currency, country=None): currency = "USD" if apply_rounding and amount % 100 != 0: - amount = ceil(amount + 100 - amount % 100) + amount = amount + 100 - amount % 100 return amount, currency @@ -1028,12 +1028,13 @@ def record_payment(address, response, client, doctype, docname): "amount_with_gst": payment_details["amount_with_gst"], "gstin": address.gstin, "pan": address.pan, + "source": address.source, "payment_for_document_type": doctype, "payment_for_document": docname, } ) payment_doc.save(ignore_permissions=True) - return payment_doc.name + return payment_doc def get_payment_details(doctype, docname, address): @@ -1056,7 +1057,7 @@ def get_payment_details(doctype, docname, address): def create_membership(course, payment): membership = frappe.new_doc("LMS Enrollment") membership.update( - {"member": frappe.session.user, "course": course, "payment": payment} + {"member": frappe.session.user, "course": course, "payment": payment.name} ) membership.save(ignore_permissions=True) return f"/courses/{course}/learn/1.1" @@ -1067,7 +1068,8 @@ def add_student_to_batch(batchname, payment): student.update( { "student": frappe.session.user, - "payment": payment, + "payment": payment.name, + "source": payment.source, "parent": batchname, "parenttype": "LMS Batch", "parentfield": "students", diff --git a/lms/patches.txt b/lms/patches.txt index 3b2e34a98..1eaa79d8c 100644 --- a/lms/patches.txt +++ b/lms/patches.txt @@ -75,4 +75,5 @@ lms.patches.v1_0.create_student_role lms.patches.v1_0.mark_confirmation_for_batch_students lms.patches.v1_0.create_quiz_questions lms.patches.v1_0.add_default_marks #16-10-2023 -lms.patches.v1_0.add_certificate_template #26-10-2023 \ No newline at end of file +lms.patches.v1_0.add_certificate_template #26-10-2023 +lms.patches.v1_0.create_batch_source \ No newline at end of file diff --git a/lms/patches/v1_0/create_batch_source.py b/lms/patches/v1_0/create_batch_source.py new file mode 100644 index 000000000..5c70da3de --- /dev/null +++ b/lms/patches/v1_0/create_batch_source.py @@ -0,0 +1,5 @@ +from lms.install import create_batch_source + + +def execute(): + create_batch_source() diff --git a/lms/www/billing/billing.js b/lms/www/billing/billing.js index 3be9b310f..ba387345e 100644 --- a/lms/www/billing/billing.js +++ b/lms/www/billing/billing.js @@ -40,15 +40,15 @@ const setup_billing = () => { reqd: 1, default: address && address.city, }, - { - fieldtype: "Column Break", - }, { fieldtype: "Data", label: __("State/Province"), fieldname: "state", default: address && address.state, }, + { + fieldtype: "Column Break", + }, { fieldtype: "Link", label: __("Country"), @@ -75,6 +75,13 @@ const setup_billing = () => { reqd: 1, default: address && address.phone, }, + { + fieldtype: "Link", + label: __("Where did you hear about this?"), + fieldname: "source", + options: "LMS Source", + only_select: 1, + }, { fieldtype: "Section Break", label: __("GST Details"), From bb23b78a4f75f981728661433277000bf0076b84 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 26 Oct 2023 18:00:11 +0530 Subject: [PATCH 2/3] fix: made source mandatory in billing form --- lms/www/billing/billing.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lms/www/billing/billing.js b/lms/www/billing/billing.js index ba387345e..484f9bb4c 100644 --- a/lms/www/billing/billing.js +++ b/lms/www/billing/billing.js @@ -81,6 +81,7 @@ const setup_billing = () => { fieldname: "source", options: "LMS Source", only_select: 1, + reqd: 1, }, { fieldtype: "Section Break", From cb6013a7a6cadbe31bfb1b7a6a420f325bb91fdf Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 26 Oct 2023 18:09:05 +0530 Subject: [PATCH 3/3] fix: source doctype name during install --- lms/install.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lms/install.py b/lms/install.py index e77cad23c..cd74c28d3 100644 --- a/lms/install.py +++ b/lms/install.py @@ -191,7 +191,7 @@ def create_batch_source(): ] for source in sources: - if not frappe.db.exists("LMS Batch Source", source): - doc = frappe.new_doc("LMS Batch Source") + if not frappe.db.exists("LMS Source", source): + doc = frappe.new_doc("LMS Source") doc.source = source doc.save()