From 63da1e384d35d39df6b281ef9fb7e659f0ba193d Mon Sep 17 00:00:00 2001
From: Jannat Patel <pateljannat2308@gmail.com>
Date: Fri, 17 Jan 2025 13:00:35 +0530
Subject: [PATCH 1/3] fix: changed the naming for certificate and job
 opportunity

---
 .../job_opportunity/job_opportunity.js        |  5 +-
 .../job_opportunity/job_opportunity.json      |  4 +-
 .../job_opportunity/job_opportunity.py        |  7 ++-
 lms/lms/doctype/lms_batch/lms_batch.js        |  5 +-
 .../lms_certificate/lms_certificate.json      |  4 +-
 .../lms_certificate/lms_certificate.py        | 53 +++++++++++++++----
 6 files changed, 59 insertions(+), 19 deletions(-)

diff --git a/lms/job/doctype/job_opportunity/job_opportunity.js b/lms/job/doctype/job_opportunity/job_opportunity.js
index bfc6891fa..b8ba1c66e 100644
--- a/lms/job/doctype/job_opportunity/job_opportunity.js
+++ b/lms/job/doctype/job_opportunity/job_opportunity.js
@@ -4,6 +4,9 @@
 frappe.ui.form.on("Job Opportunity", {
 	refresh: (frm) => {
 		if (frm.doc.name)
-			frm.add_web_link(`/job-openings/${frm.doc.name}`, "See on Website");
+			frm.add_web_link(
+				`/lms/job-openings/${frm.doc.name}`,
+				"See on Website"
+			);
 	},
 });
diff --git a/lms/job/doctype/job_opportunity/job_opportunity.json b/lms/job/doctype/job_opportunity/job_opportunity.json
index 44ae05d2a..d6ed5c4b5 100644
--- a/lms/job/doctype/job_opportunity/job_opportunity.json
+++ b/lms/job/doctype/job_opportunity/job_opportunity.json
@@ -2,7 +2,6 @@
  "actions": [],
  "allow_import": 1,
  "allow_rename": 1,
- "autoname": "format: JOB-{#####}",
  "creation": "2022-02-07 12:01:41.074418",
  "doctype": "DocType",
  "editable_grid": 1,
@@ -117,11 +116,10 @@
  "index_web_pages_for_search": 1,
  "links": [],
  "make_attachments_public": 1,
- "modified": "2024-02-07 23:02:06.102120",
+ "modified": "2025-01-17 12:38:57.134919",
  "modified_by": "Administrator",
  "module": "Job",
  "name": "Job Opportunity",
- "naming_rule": "Expression",
  "owner": "Administrator",
  "permissions": [
   {
diff --git a/lms/job/doctype/job_opportunity/job_opportunity.py b/lms/job/doctype/job_opportunity/job_opportunity.py
index 77c16a6f8..ce711216d 100644
--- a/lms/job/doctype/job_opportunity/job_opportunity.py
+++ b/lms/job/doctype/job_opportunity/job_opportunity.py
@@ -6,8 +6,7 @@
 from frappe.model.document import Document
 from frappe.utils import get_link_to_form, add_months, getdate
 from frappe.utils.user import get_system_managers
-
-from lms.lms.utils import validate_image
+from lms.lms.utils import validate_image, generate_slug
 
 
 class JobOpportunity(Document):
@@ -18,6 +17,10 @@ def validate(self):
 	def validate_urls(self):
 		frappe.utils.validate_url(self.company_website, True)
 
+	def autoname(self):
+		if not self.name:
+			self.name = generate_slug(f"{self.job_title}-${self.company_name}", "LMS Course")
+
 
 def update_job_openings():
 	old_jobs = frappe.get_all(
diff --git a/lms/lms/doctype/lms_batch/lms_batch.js b/lms/lms/doctype/lms_batch/lms_batch.js
index c7db974d3..f196c867b 100644
--- a/lms/lms/doctype/lms_batch/lms_batch.js
+++ b/lms/lms/doctype/lms_batch/lms_batch.js
@@ -48,7 +48,10 @@ frappe.ui.form.on("LMS Batch", {
 	},
 
 	refresh: (frm) => {
-		frm.add_web_link(`/batches/details/${frm.doc.name}`, "See on website");
+		frm.add_web_link(
+			`/lms/batches/details/${frm.doc.name}`,
+			"See on website"
+		);
 	},
 });
 
diff --git a/lms/lms/doctype/lms_certificate/lms_certificate.json b/lms/lms/doctype/lms_certificate/lms_certificate.json
index e53e9342e..c4f74e7f9 100644
--- a/lms/lms/doctype/lms_certificate/lms_certificate.json
+++ b/lms/lms/doctype/lms_certificate/lms_certificate.json
@@ -1,7 +1,6 @@
 {
  "actions": [],
  "allow_import": 1,
- "autoname": "hash",
  "creation": "2021-08-16 15:47:19.494055",
  "doctype": "DocType",
  "editable_grid": 1,
@@ -123,11 +122,10 @@
  ],
  "index_web_pages_for_search": 1,
  "links": [],
- "modified": "2025-01-16 12:12:49.998114",
+ "modified": "2025-01-17 11:57:02.859109",
  "modified_by": "Administrator",
  "module": "LMS",
  "name": "LMS Certificate",
- "naming_rule": "Random",
  "owner": "Administrator",
  "permissions": [
   {
diff --git a/lms/lms/doctype/lms_certificate/lms_certificate.py b/lms/lms/doctype/lms_certificate/lms_certificate.py
index c85643c6f..932c3dcca 100644
--- a/lms/lms/doctype/lms_certificate/lms_certificate.py
+++ b/lms/lms/doctype/lms_certificate/lms_certificate.py
@@ -7,12 +7,16 @@
 from frappe.utils import add_years, nowdate
 from lms.lms.utils import is_certified
 from frappe.email.doctype.email_template.email_template import get_email_template
+from frappe.model.naming import make_autoname
 
 
 class LMSCertificate(Document):
 	def validate(self):
 		self.validate_duplicate_certificate()
 
+	def autoname(self):
+		self.name = make_autoname("hash", self.doctype)
+
 	def after_insert(self):
 		if not frappe.flags.in_test:
 			outgoing_email_account = frappe.get_cached_value(
@@ -48,16 +52,47 @@ def send_mail(self):
 		)
 
 	def validate_duplicate_certificate(self):
-		certificates = frappe.get_all(
-			"LMS Certificate",
-			{"member": self.member, "course": self.course, "name": ["!=", self.name]},
-		)
-		if len(certificates):
-			full_name = frappe.db.get_value("User", self.member, "full_name")
-			course_name = frappe.db.get_value("LMS Course", self.course, "title")
-			frappe.throw(
-				_("{0} is already certified for the course {1}").format(full_name, course_name)
+		self.validate_course_duplicates()
+		self.validate_batch_duplicates()
+
+	def validate_course_duplicates(self):
+		if self.course:
+			course_duplicates = frappe.get_all(
+				"LMS Certificate",
+				filters={
+					"member": self.member,
+					"name": ["!=", self.name],
+					"course": self.course,
+				},
+				fields=["name", "course", "course_title"],
+			)
+			if len(course_duplicates):
+				full_name = frappe.db.get_value("User", self.member, "full_name")
+				frappe.throw(
+					_("{0} is already certified for the course {1}").format(
+						full_name, course_duplicates[0].course_title
+					)
+				)
+
+	def validate_batch_duplicates(self):
+		if self.batch_name:
+			batch_duplicates = frappe.get_all(
+				"LMS Certificate",
+				filters={
+					"member": self.member,
+					"name": ["!=", self.name],
+					"batch_name": self.batch_name,
+				},
+				fields=["name", "batch_name", "batch_title"],
 			)
+			if len(batch_duplicates):
+				print(batch_duplicates)
+				full_name = frappe.db.get_value("User", self.member, "full_name")
+				frappe.throw(
+					_("{0} is already certified for the batch {1}").format(
+						full_name, batch_duplicates[0].batch_title
+					)
+				)
 
 	def on_update(self):
 		frappe.share.add_docshare(

From 4f0a6a7d5709556aef2efe5e571a38872534effe Mon Sep 17 00:00:00 2001
From: Jannat Patel <pateljannat2308@gmail.com>
Date: Fri, 17 Jan 2025 14:18:07 +0530
Subject: [PATCH 2/3] chore: removed print statement

---
 lms/lms/doctype/lms_certificate/lms_certificate.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lms/lms/doctype/lms_certificate/lms_certificate.py b/lms/lms/doctype/lms_certificate/lms_certificate.py
index 932c3dcca..7adb21cd8 100644
--- a/lms/lms/doctype/lms_certificate/lms_certificate.py
+++ b/lms/lms/doctype/lms_certificate/lms_certificate.py
@@ -86,7 +86,6 @@ def validate_batch_duplicates(self):
 				fields=["name", "batch_name", "batch_title"],
 			)
 			if len(batch_duplicates):
-				print(batch_duplicates)
 				full_name = frappe.db.get_value("User", self.member, "full_name")
 				frappe.throw(
 					_("{0} is already certified for the batch {1}").format(

From 9dc832227020fb40bcc40f2453d7e3517cb8bbf2 Mon Sep 17 00:00:00 2001
From: Jannat Patel <pateljannat2308@gmail.com>
Date: Fri, 17 Jan 2025 14:24:14 +0530
Subject: [PATCH 3/3] fix: don't check assignment submission status if doc is
 new

---
 .../lms_assignment_submission.py                         | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py b/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py
index a1c30cbe7..dcb7f71d5 100644
--- a/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py
+++ b/lms/lms/doctype/lms_assignment_submission/lms_assignment_submission.py
@@ -72,9 +72,12 @@ def send_mail(self):
 		)
 
 	def validate_status(self):
-		doc_before_save = self.get_doc_before_save()
-		if doc_before_save.status != self.status or doc_before_save.comments != self.comments:
-			self.trigger_update_notification()
+		if not self.is_new():
+			doc_before_save = self.get_doc_before_save()
+			if (
+				doc_before_save.status != self.status or doc_before_save.comments != self.comments
+			):
+				self.trigger_update_notification()
 
 	def trigger_update_notification(self):
 		notification = frappe._dict(