From 1b75334144b367cea2ae190d2a2f6b9147d8a3ad Mon Sep 17 00:00:00 2001 From: krantheman Date: Tue, 12 Dec 2023 18:38:50 +0530 Subject: [PATCH] refactor: use single monthly_earned_leave --- .../leave_allocation/leave_allocation.js | 9 ++++--- .../leave_allocation_dashboard.html | 8 +++--- hrms/hr/utils.py | 25 ++++++++----------- hrms/www/jobs/__init__.py | 0 4 files changed, 20 insertions(+), 22 deletions(-) delete mode 100644 hrms/www/jobs/__init__.py diff --git a/hrms/hr/doctype/leave_allocation/leave_allocation.js b/hrms/hr/doctype/leave_allocation/leave_allocation.js index d90f946938..bff38e46f3 100755 --- a/hrms/hr/doctype/leave_allocation/leave_allocation.js +++ b/hrms/hr/doctype/leave_allocation/leave_allocation.js @@ -195,7 +195,7 @@ frappe.ui.form.on("Leave Allocation", { rounding: frm.rounding, }, callback: function (r) { - frm.monthly_leaves = r.message; + frm.monthly_earned_leave = r.message; frm.new_leaves = r.message; frm.trigger("make_dashboard"); }, @@ -230,18 +230,19 @@ frappe.ui.form.on("Leave Allocation", { $("div").remove(".form-dashboard-section.custom"); frappe.call({ - method: "hrms.hr.utils.get_monthly_allocations", + method: "hrms.hr.utils.get_monthly_allocation_dates", args: { - employee: frm.doc.employee, leave_type: frm.doc.leave_type, from_date: frm.doc.from_date, to_date: frm.doc.to_date, leave_policy: frm.doc.leave_policy, + monthly_earned_leave: frm.monthly_earned_leave, }, callback: function (r) { frm.dashboard.add_section( frappe.render_template("leave_allocation_dashboard", { - allocations: r.message + allocation_dates: r.message, + monthly_earned_leave: frm.monthly_earned_leave, }), __("Leaves Allocated") ); diff --git a/hrms/hr/doctype/leave_allocation/leave_allocation_dashboard.html b/hrms/hr/doctype/leave_allocation/leave_allocation_dashboard.html index 4baed7ebf8..2b2ab83f47 100644 --- a/hrms/hr/doctype/leave_allocation/leave_allocation_dashboard.html +++ b/hrms/hr/doctype/leave_allocation/leave_allocation_dashboard.html @@ -1,4 +1,4 @@ -{% if allocations.length %} +{% if allocation_dates.length %} @@ -7,10 +7,10 @@ - {% for(const i of allocations) { %} {% %} + {% for(const date of allocation_dates) { %} {% %} - - + + {% } %} diff --git a/hrms/hr/utils.py b/hrms/hr/utils.py index 7b727c7b95..f26c1ec548 100644 --- a/hrms/hr/utils.py +++ b/hrms/hr/utils.py @@ -523,33 +523,30 @@ def allocate_leaves_manually(allocation_name, new_leaves): @frappe.whitelist() -def get_monthly_allocations(employee, leave_type, from_date, to_date, leave_policy): +def get_monthly_allocation_dates( + leave_type, from_date, to_date, leave_policy, monthly_earned_leave +): annual_allocation = frappe.db.get_value( "Leave Policy Detail", {"parent": leave_policy, "leave_type": leave_type}, "annual_allocation" ) - date_of_joining = frappe.db.get_value("Employee", employee, "date_of_joining") - allocate_on_day, rounding = frappe.db.get_value( - "Leave Type", leave_type, ["allocate_on_day", "rounding"] - ) - monthly_earned_leave = get_monthly_earned_leave( - date_of_joining, annual_allocation, "Monthly", rounding, pro_rated=False - ) + allocate_on_day = frappe.db.get_value("Leave Type", leave_type, "allocate_on_day") + date = get_month_allocation_date(from_date, allocate_on_day) allocations = [] - date = get_monthly_allocation_date(from_date, allocate_on_day) - total_leaves = 0 + monthly_earned_leave = float(monthly_earned_leave) + total_leaves = monthly_earned_leave if date < from_date: date = add_months(date, 1) - date = get_monthly_allocation_date(date, allocate_on_day) + date = get_month_allocation_date(date, allocate_on_day) while date <= to_date and total_leaves <= annual_allocation: - allocations.append({"date": date, "leaves": monthly_earned_leave}) + allocations.append(date) date = add_months(date, 1) - date = get_monthly_allocation_date(date, allocate_on_day) + date = get_month_allocation_date(date, allocate_on_day) total_leaves += monthly_earned_leave return allocations -def get_monthly_allocation_date(date, allocate_on_day): +def get_month_allocation_date(date, allocate_on_day): allocation_date = { "First Day": get_first_day(date), "Last Day": get_last_day(date), diff --git a/hrms/www/jobs/__init__.py b/hrms/www/jobs/__init__.py deleted file mode 100644 index e69de29bb2..0000000000
{%= i.date %}{%= i.leaves %}{%= date %}{%= monthly_earned_leave %}