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", { frappe.ui.form.on("Job Opportunity", {
refresh: (frm) => { refresh: (frm) => {
if (frm.doc.name) 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": [], "actions": [],
"allow_import": 1, "allow_import": 1,
"allow_rename": 1, "allow_rename": 1,
"autoname": "format: JOB-{#####}",
"creation": "2022-02-07 12:01:41.074418", "creation": "2022-02-07 12:01:41.074418",
"doctype": "DocType", "doctype": "DocType",
"editable_grid": 1, "editable_grid": 1,
@@ -117,11 +116,10 @@
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"make_attachments_public": 1, "make_attachments_public": 1,
"modified": "2024-02-07 23:02:06.102120", "modified": "2025-01-17 12:38:57.134919",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Job", "module": "Job",
"name": "Job Opportunity", "name": "Job Opportunity",
"naming_rule": "Expression",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {

View File

@@ -6,8 +6,7 @@ from frappe import _
from frappe.model.document import Document from frappe.model.document import Document
from frappe.utils import get_link_to_form, add_months, getdate from frappe.utils import get_link_to_form, add_months, getdate
from frappe.utils.user import get_system_managers from frappe.utils.user import get_system_managers
from lms.lms.utils import validate_image, generate_slug
from lms.lms.utils import validate_image
class JobOpportunity(Document): class JobOpportunity(Document):
@@ -18,6 +17,10 @@ class JobOpportunity(Document):
def validate_urls(self): def validate_urls(self):
frappe.utils.validate_url(self.company_website, True) 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(): def update_job_openings():
old_jobs = frappe.get_all( old_jobs = frappe.get_all(

View File

@@ -48,7 +48,10 @@ frappe.ui.form.on("LMS Batch", {
}, },
refresh: (frm) => { 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": [], "actions": [],
"allow_import": 1, "allow_import": 1,
"autoname": "hash",
"creation": "2021-08-16 15:47:19.494055", "creation": "2021-08-16 15:47:19.494055",
"doctype": "DocType", "doctype": "DocType",
"editable_grid": 1, "editable_grid": 1,
@@ -123,11 +122,10 @@
], ],
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"links": [], "links": [],
"modified": "2025-01-16 12:12:49.998114", "modified": "2025-01-17 11:57:02.859109",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "LMS", "module": "LMS",
"name": "LMS Certificate", "name": "LMS Certificate",
"naming_rule": "Random",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {

View File

@@ -7,12 +7,16 @@ from frappe.model.document import Document
from frappe.utils import add_years, nowdate from frappe.utils import add_years, nowdate
from lms.lms.utils import is_certified from lms.lms.utils import is_certified
from frappe.email.doctype.email_template.email_template import get_email_template from frappe.email.doctype.email_template.email_template import get_email_template
from frappe.model.naming import make_autoname
class LMSCertificate(Document): class LMSCertificate(Document):
def validate(self): def validate(self):
self.validate_duplicate_certificate() self.validate_duplicate_certificate()
def autoname(self):
self.name = make_autoname("hash", self.doctype)
def after_insert(self): def after_insert(self):
if not frappe.flags.in_test: if not frappe.flags.in_test:
outgoing_email_account = frappe.get_cached_value( outgoing_email_account = frappe.get_cached_value(
@@ -48,16 +52,47 @@ class LMSCertificate(Document):
) )
def validate_duplicate_certificate(self): def validate_duplicate_certificate(self):
certificates = frappe.get_all( self.validate_course_duplicates()
"LMS Certificate", self.validate_batch_duplicates()
{"member": self.member, "course": self.course, "name": ["!=", self.name]},
) def validate_course_duplicates(self):
if len(certificates): if self.course:
full_name = frappe.db.get_value("User", self.member, "full_name") course_duplicates = frappe.get_all(
course_name = frappe.db.get_value("LMS Course", self.course, "title") "LMS Certificate",
frappe.throw( filters={
_("{0} is already certified for the course {1}").format(full_name, course_name) "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): def on_update(self):
frappe.share.add_docshare( frappe.share.add_docshare(