fix: changed the naming for certificate and job opportunity

This commit is contained in:
Jannat Patel
2025-01-17 13:00:35 +05:30
parent 34685ebdb2
commit 63da1e384d
6 changed files with 59 additions and 19 deletions

View File

@@ -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"
);
},
});

View File

@@ -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": [
{

View File

@@ -6,8 +6,7 @@ from frappe import _
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 @@ class JobOpportunity(Document):
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(

View File

@@ -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"
);
},
});

View File

@@ -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": [
{

View File

@@ -7,12 +7,16 @@ from frappe.model.document import Document
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 @@ class LMSCertificate(Document):
)
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(