Skip to content

Commit

Permalink
Merge pull request #1256 from pateljannat/issues-68
Browse files Browse the repository at this point in the history
fix: changed the naming for certificate and job opportunity
  • Loading branch information
pateljannat authored Jan 17, 2025
2 parents 34685eb + 9dc8322 commit 58abfd0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 22 deletions.
5 changes: 4 additions & 1 deletion lms/job/doctype/job_opportunity/job_opportunity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
},
});
4 changes: 1 addition & 3 deletions lms/job/doctype/job_opportunity/job_opportunity.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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": [
{
Expand Down
7 changes: 5 additions & 2 deletions lms/job/doctype/job_opportunity/job_opportunity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 4 additions & 1 deletion lms/lms/doctype/lms_batch/lms_batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
},
});

Expand Down
4 changes: 1 addition & 3 deletions lms/lms/doctype/lms_certificate/lms_certificate.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"actions": [],
"allow_import": 1,
"autoname": "hash",
"creation": "2021-08-16 15:47:19.494055",
"doctype": "DocType",
"editable_grid": 1,
Expand Down Expand Up @@ -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": [
{
Expand Down
52 changes: 43 additions & 9 deletions lms/lms/doctype/lms_certificate/lms_certificate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -48,16 +52,46 @@ 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):
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(
Expand Down

0 comments on commit 58abfd0

Please sign in to comment.