Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: expire_allocation api endpoint by fetching allocation object #1576

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hrms/hr/doctype/leave_allocation/leave_allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ frappe.ui.form.on("Leave Allocation", {
refresh: function (frm) {
hrms.leave_utils.add_view_ledger_button(frm);

if (frm.doc.docstatus === 1 && frm.doc.expired) {
if (frm.doc.docstatus === 1 && !frm.doc.expired) {
var valid_expiry = moment(frappe.datetime.get_today()).isBetween(
frm.doc.from_date,
frm.doc.to_date,
Expand Down
7 changes: 6 additions & 1 deletion hrms/hr/doctype/leave_ledger_entry/leave_ledger_entry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt


import frappe
from frappe import _
from frappe.model.document import Document
Expand Down Expand Up @@ -185,6 +184,12 @@ def get_remaining_leaves(allocation):
@frappe.whitelist()
def expire_allocation(allocation, expiry_date=None):
"""expires non-carry forwarded allocation"""
import json

if isinstance(allocation, str):
allocation = json.loads(allocation)
allocation = frappe.get_doc("Leave Allocation", allocation["name"])

leaves = get_remaining_leaves(allocation)
expiry_date = expiry_date if expiry_date else allocation.to_date

Expand Down
39 changes: 37 additions & 2 deletions hrms/hr/doctype/leave_ledger_entry/test_leave_ledger_entry.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,44 @@
# Copyright (c) 2019, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt

# import frappe
import frappe
from frappe.tests.utils import FrappeTestCase
from frappe.utils.data import add_to_date, today

from erpnext.setup.doctype.employee.test_employee import make_employee

from hrms.hr.doctype.leave_ledger_entry.leave_ledger_entry import expire_allocation


class TestLeaveLedgerEntry(FrappeTestCase):
pass
def setUp(self):
emp_id = make_employee("[email protected]", company="_Test Company")
self.employee = frappe.get_doc("Employee", emp_id)

def test_expire_allocation(self):
import json

allocation = {
"doctype": "Leave Allocation",
"__islocal": 1,
"employee": self.employee.name,
"employee_name": self.employee.employee_name,
"leave_type": "_Test Leave Type",
"from_date": today(),
"to_date": add_to_date(today(), days=30),
"new_leaves_allocated": 5,
"docstatus": 1,
}

allocation = frappe.get_doc(allocation).save()

expire_allocation(json.dumps(allocation.as_dict()))
allocation.reload()

self.assertEqual(allocation.expired, 1)

def tearDown(self):
frappe.db.rollback()


test_dependencies = ["Employee", "Leave Type"]
Loading