Skip to content

Commit

Permalink
Merge pull request #129 from ju-omari21/refact
Browse files Browse the repository at this point in the history
Adding Faculty Member Reports
  • Loading branch information
alshalabi-su authored Jul 30, 2024
2 parents 40be27c + 39e6301 commit 3317b1c
Show file tree
Hide file tree
Showing 11 changed files with 293 additions and 116 deletions.
13 changes: 13 additions & 0 deletions academia/academia/doctype/faculty_member/faculty_member.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,19 @@ frappe.ui.form.on('Faculty Member', {
}
});

frappe.ui.form.on('Faculty Member Academic Ranking', {
academic_rank: function(frm, cdt, cdn) {
frappe.call({
method: 'academia.academia.doctype.faculty_member.faculty_member.update_academic_rank',
args: {
doc: frm.doc
},
callback: function(response) {
frm.refresh_field('academic_rank');
}
});
}
});



Expand Down
4 changes: 2 additions & 2 deletions academia/academia/doctype/faculty_member/faculty_member.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
{
"fieldname": "employee",
"fieldtype": "Link",
"label": "Employee ",
"label": "Employee",
"options": "Employee",
"reqd": 1
},
Expand Down Expand Up @@ -437,7 +437,7 @@
"link_fieldname": "faculty_member"
}
],
"modified": "2024-07-28 12:15:40.044501",
"modified": "2024-07-30 11:41:28.722731",
"modified_by": "Administrator",
"module": "Academia",
"name": "Faculty Member",
Expand Down
77 changes: 24 additions & 53 deletions academia/academia/doctype/faculty_member/faculty_member.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
# Copyright (c) 2024, SanU and contributors
# For license information, please see license.txt

import frappe
from frappe.model.document import Document
from frappe import _
import re
from datetime import datetime, timedelta
from datetime import datetime
from frappe.utils import add_months, nowdate
import logging


class FacultyMember(Document):
# begin: auto-generated types
# This code is auto-generated. Do not modify anything in this block.

# Begin auto-generated types
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand Down Expand Up @@ -42,6 +37,7 @@ class FacultyMember(Document):
email: DF.Data | None
employee: DF.Link
employment_type: DF.Link | None
external_faculty: DF.Link | None
faculty: DF.Link
faculty_member_academic_ranking: DF.Table[FacultyMemberAcademicRanking]
faculty_member_activity: DF.Table[FacultyMemberActivity]
Expand All @@ -63,8 +59,8 @@ class FacultyMember(Document):
scientific_degree: DF.Link
specialist_field: DF.Data | None
tenure_status: DF.Literal["", "On Probation", "Tenured"]
# end: auto-generated types
# End auto-generated types

# Start of validate controller hook
def validate(self):
# Calling functions
Expand All @@ -76,15 +72,14 @@ def validate(self):
self.check_tenure_eligibility()
# End of validate controller hook

# FN: validate duplicate 'employee' field
# Validate duplicate 'employee' field
def validate_duplicate_employee(self):
if self.employee:
exist_employee = frappe.get_value("Faculty Member", {"employee": self.employee, "name": ["!=", self.name]}, "faculty_member_name")
if exist_employee:
frappe.throw(_(f"Employee {self.employee} is already assigned to {exist_employee}"))
# End of the function

# FN: validate 'date_of_joining_in_university' and 'date_of_joining_in_service' and 'date in tenure data' fields
# Validate 'date_of_joining_in_university' and 'date_of_joining_in_service' and 'date in tenure data' fields
def validate_date(self):
today = frappe.utils.today()

Expand All @@ -104,53 +99,21 @@ def validate_date(self):
if self.date > today:
frappe.throw(_("Date in tenure data section cannot be in the future."))

# End of the function

# FN: validate 'google_scholar_profile_link' field
# Validate 'google_scholar_profile_link' field
def validate_url(self):
url_pattern = re.compile(r'^(http|https|ftp)://\S+$')
if self.google_scholar_profile_link:
if not url_pattern.match(self.google_scholar_profile_link):
frappe.throw(_("Google Scholar Profile Link is not valid. Please enter a valid URL starting with http, https, or ftp."))
# End of the function

# FN: validate 'decision_number' field
# Validate 'decision_number' field
def validate_decision_number(self):
if self.decision_number and not self.decision_number.isdigit():
frappe.throw(_("Decision Number should contain only digits."))
# End of the function

# def get_probation_end_date(self):
# if self.date_of_joining_in_university and self.tenure_status == "On Probation":
# faculty_member_settings = frappe.get_all(
# "Faculty Member Settings",
# filters=[
# ["academic_rank", "=", self.academic_rank],
# ["valid_from", "<=", self.date_of_joining_in_university],
# ],
# fields=["name", "probation_period"],
# order_by="valid_from desc",
# )

# # Check if results are found before accessing elements
# if faculty_member_settings:
# faculty_member_settings = faculty_member_settings[0]
# self.probation_period_end_date = add_months(
# self.date_of_joining_in_university,
# int(faculty_member_settings.probation_period),
# )
# else:
# # Handle missing settings gracefully (optional)
# frappe.msgprint(
# _(
# "Probation periods not found in Faculty Member Settings for <b>{self.academic_rank}</b>. Please create appropriate settings."
# ),
# title=_("Missing Probation Settings"),
# indicator="orange",
# )
# Fetch and set probation end date
def get_probation_end_date(self):
if self.date_of_joining_in_university and self.tenure_status == "On Probation":
# Fetch settings with filters
faculty_member_settings = frappe.get_all(
"Faculty Member Settings",
filters=[
Expand All @@ -161,24 +124,21 @@ def get_probation_end_date(self):
order_by="valid_from desc",
)

# Check if results are found before accessing elements
if faculty_member_settings:
faculty_member_settings = faculty_member_settings[0]
self.probation_period_end_date = add_months(
self.date_of_joining_in_university,
int(faculty_member_settings.probation_period),
)
else:
# Raise an exception to prevent saving the document
frappe.throw(
_(
"Probation periods not found in Faculty Member Settings for <b>{}</b> from this date. Please create appropriate settings.".format(self.academic_rank)
),
title=_("Missing Probation Settings"),
)



# Check tenure eligibility
def check_tenure_eligibility(self):
if self.probation_period_end_date:
try:
Expand All @@ -191,8 +151,19 @@ def check_tenure_eligibility(self):
self.is_eligible_for_granting_tenure = 0

except ValueError as e:
# Handle date format errors
frappe.msgprint(_("Error parsing probation end date: {0}").format(e), title=_("Date Parsing Error"), indicator="red")
self.is_eligible_for_granting_tenure = 0


@frappe.whitelist()
def update_academic_rank(doc):
logging.debug(f"Updating academic rank for document: {doc}")
doc = frappe.parse_json(doc)
logging.debug(f"Parsed document: {doc}")
if 'faculty_member_academic_ranking' in doc and doc['faculty_member_academic_ranking']:
last_ranking = doc['faculty_member_academic_ranking'][-1]
logging.debug(f"Last academic ranking: {last_ranking}")
if 'academic_rank' in last_ranking:
frappe.db.set_value("Faculty Member", doc['name'], "academic_rank", last_ranking['academic_rank'])
logging.info(f"Updated academic rank to {last_ranking['academic_rank']} for Faculty Member {doc['name']}")
return last_ranking['academic_rank']
return None
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@

frappe.query_reports["Faculty Member Details Report"] = {
filters: [
{
fieldname: "from_date",
label: __("From Date"),
fieldtype: "Date",
reqd: 1,
default: frappe.defaults.get_default("year_start_date")
},
{
fieldname: "to_date",
label: __("To Date"),
fieldtype: "Date",
reqd: 1,
default: frappe.defaults.get_default("year_end_date")
},
// {
// fieldname: "from_date",
// label: __("From Date"),
// fieldtype: "Date",
// reqd: 1,
// default: frappe.defaults.get_default("year_start_date")
// },
// {
// fieldname: "to_date",
// label: __("To Date"),
// fieldtype: "Date",
// reqd: 1,
// default: frappe.defaults.get_default("year_end_date")
// },
{
label: __("Faculty"),
fieldname: "faculty",
Expand All @@ -26,22 +26,23 @@ frappe.query_reports["Faculty Member Details Report"] = {
default: frappe.defaults.get_user_default("Company")
},
{
label: __("Date of Joining"),
fieldname: "date_of_joining_in_university",
fieldtype: "Date",
},
{
label: __("Employment Type"),
fieldname: "employment_type",
fieldtype: "Link",
options: "Employment Type",
},
{
fieldname: "academic_rank",
label: __("Academic Rank"),
label: __("Employee"),
fieldname: "employee",
fieldtype: "Link",
options: "Academic Rank",
options: "Employee",
},
// {
// label: __("Employment Type"),
// fieldname: "employment_type",
// fieldtype: "Link",
// options: "Employment Type",
// },
// {
// fieldname: "academic_rank",
// label: __("Academic Rank"),
// fieldtype: "Link",
// options: "Academic Rank",
// },
{
fieldname: "employee_status",
label: __("Employee Status"),
Expand All @@ -54,6 +55,13 @@ frappe.query_reports["Faculty Member Details Report"] = {
{ "value": "Left", "label": __("Left") },
],
default: "Active",
}
},
// {
// fieldname: "consolidate_leave_types",
// label: __("Consolidate Leave Types"),
// fieldtype: "Check",
// default: 1,
// depends_on: "eval: !doc.employee",
// }
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
"is_standard": "Yes",
"json": "{}",
"letterhead": null,
"modified": "2024-07-29 14:40:03.697915",
"modified": "2024-07-29 23:36:24.383067",
"modified_by": "Administrator",
"module": "Academia",
"name": "Faculty Member Details Report",
"owner": "Administrator",
"prepared_report": 0,
"ref_doctype": "Faculty Member",
"report_name": "Faculty Member Details Report",
"report_type": "Report Builder",
"report_type": "Script Report",
"roles": [
{
"role": "HR User"
Expand Down
Loading

0 comments on commit 3317b1c

Please sign in to comment.