Skip to content

Commit

Permalink
Merge pull request #2549 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
chore: release v14
  • Loading branch information
ruchamahabal authored Dec 27, 2024
2 parents df56dfa + 937ec3b commit 6116552
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 14 deletions.
31 changes: 26 additions & 5 deletions hrms/hr/doctype/leave_allocation/leave_allocation.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,22 +70,43 @@ frappe.ui.form.on("Leave Allocation", {
label: "New Leaves to be Allocated",
fieldname: "new_leaves",
fieldtype: "Float",
reqd: 1,
},
{
label: "From Date",
fieldname: "from_date",
fieldtype: "Date",
default: frappe.datetime.get_today(),
},
{
label: "To Date",
fieldname: "to_date",
fieldtype: "Date",
read_only: 1,
default: frm.doc.to_date,
},
],
primary_action_label: "Allocate",
primary_action({ new_leaves }) {
primary_action({ new_leaves, from_date }) {
frappe.call({
method: "allocate_leaves_manually",
doc: frm.doc,
args: { new_leaves },
callback: function () {
frm.reload_doc();
args: { new_leaves, from_date },
callback: function (r) {
if (!r.exc) {
dialog.hide();
frm.reload_doc();
}
},
});
dialog.hide();
},
});
dialog.fields_dict.new_leaves.set_value(monthly_earned_leave);
dialog.fields_dict.from_date.datepicker?.update({
minDate: frappe.datetime.str_to_obj(frm.doc.from_date),
maxDate: frappe.datetime.str_to_obj(frm.doc.to_date),
});

dialog.show();
},
__("Actions"),
Expand Down
17 changes: 15 additions & 2 deletions hrms/hr/doctype/leave_allocation/leave_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,15 @@ def create_leave_ledger_entry(self, submit=True):
create_leave_ledger_entry(self, args, submit)

@frappe.whitelist()
def allocate_leaves_manually(self, new_leaves):
def allocate_leaves_manually(self, new_leaves, from_date=None):
if from_date and not (getdate(self.from_date) <= getdate(from_date) <= getdate(self.to_date)):
frappe.throw(
_("Cannot allocate leaves outside the allocation period {0} - {1}").format(
frappe.bold(formatdate(self.from_date)), frappe.bold(formatdate(self.to_date))
),
title=_("Invalid Dates"),
)

new_allocation = flt(self.total_leaves_allocated) + flt(new_leaves)
new_allocation_without_cf = flt(
flt(self.get_existing_leave_count()) + flt(new_leaves),
Expand All @@ -339,13 +347,18 @@ def allocate_leaves_manually(self, new_leaves):
):
self.db_set("total_leaves_allocated", new_allocation, update_modified=False)

date = frappe.flags.current_date or getdate()
date = from_date or frappe.flags.current_date or getdate()
create_additional_leave_ledger_entry(self, new_leaves, date)

text = _("{0} leaves were manually allocated by {1} on {2}").format(
frappe.bold(new_leaves), frappe.session.user, frappe.bold(formatdate(date))
)
self.add_comment(comment_type="Info", text=text)
frappe.msgprint(
_("{0} leaves allocated successfully").format(frappe.bold(new_leaves)),
indicator="green",
alert=True,
)

else:
msg = _("Total leaves allocated cannot exceed annual allocation of {0}.").format(
Expand Down
17 changes: 15 additions & 2 deletions hrms/hr/doctype/leave_allocation/test_earned_leaves.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,10 +495,23 @@ def test_allocate_leaves_manually(self):
get_leave_balance_on(self.employee.name, self.leave_type, frappe.flags.current_date), 6
)

leave_allocation.allocate_leaves_manually(6)
leave_allocation.allocate_leaves_manually(5)
self.assertEqual(
get_leave_balance_on(self.employee.name, self.leave_type, frappe.flags.current_date), 12
get_leave_balance_on(self.employee.name, self.leave_type, frappe.flags.current_date), 11
)

# manually set from_date - applicable from the next day
leave_allocation.allocate_leaves_manually(1, add_days(frappe.flags.current_date, 1))
# balance should be 11 on the current date
self.assertEqual(
get_leave_balance_on(self.employee.name, self.leave_type, frappe.flags.current_date), 11
)
# allocated leave should be applicable from the next day
self.assertEqual(
get_leave_balance_on(self.employee.name, self.leave_type, add_days(frappe.flags.current_date, 1)),
12,
)

self.assertRaises(frappe.ValidationError, leave_allocation.allocate_leaves_manually, 1)

def tearDown(self):
Expand Down
7 changes: 4 additions & 3 deletions hrms/hr/doctype/leave_type/leave_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@
{
"fieldname": "max_leaves_allowed",
"fieldtype": "Float",
"label": "Maximum Leave Allocation Allowed"
"label": "Maximum Leave Allocation Allowed per Leave Period"
},
{
"description": "Minimum working days required since Date of Joining to apply for this leave",
"fieldname": "applicable_after",
"fieldtype": "Int",
"label": "Applicable After (Working Days)"
"label": "Allow Leave Application After (Working Days)"
},
{
"fieldname": "max_continuous_days_allowed",
Expand Down Expand Up @@ -224,7 +225,7 @@
"icon": "fa fa-flag",
"idx": 1,
"links": [],
"modified": "2023-05-26 14:15:29.695487",
"modified": "2024-12-18 19:51:44.162375",
"modified_by": "Administrator",
"module": "HR",
"name": "Leave Type",
Expand Down
7 changes: 5 additions & 2 deletions hrms/hr/doctype/shift_type/shift_type.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"autoname": "prompt",
"creation": "2018-04-13 16:22:52.954783",
"doctype": "DocType",
"documentation": "https://docs.frappe.io/hr/shift-type",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
Expand Down Expand Up @@ -148,10 +149,12 @@
"label": "Enable Auto Attendance"
},
{
"default": "Today",
"description": "Attendance will be marked automatically only after this date.",
"fieldname": "process_attendance_after",
"fieldtype": "Date",
"label": "Process Attendance After"
"label": "Process Attendance After",
"mandatory_depends_on": "enable_auto_attendance"
},
{
"description": "Last Known Successful Sync of Employee Checkin. Reset this only if you are sure that all Logs are synced from all the locations. Please don't modify this if you are unsure.",
Expand All @@ -168,7 +171,7 @@
}
],
"links": [],
"modified": "2023-08-11 20:30:13.358549",
"modified": "2024-12-18 19:03:38.278336",
"modified_by": "Administrator",
"module": "HR",
"name": "Shift Type",
Expand Down

0 comments on commit 6116552

Please sign in to comment.