Skip to content

Commit

Permalink
Merge pull request #1281 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
chore: release v14
  • Loading branch information
ruchamahabal authored Jan 9, 2024
2 parents 1d4f89c + 8bd256d commit 5124c0e
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 94 deletions.
7 changes: 3 additions & 4 deletions .github/helper/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ sed -i 's/redis_socketio:/# redis_socketio:/g' Procfile

bench get-app payments --branch ${BRANCH_TO_CLONE%"-hotfix"}
bench get-app https://github.com/frappe/erpnext --branch "$BRANCH_TO_CLONE" --resolve-deps
bench get-app hrms "${GITHUB_WORKSPACE}"
bench setup requirements --dev

bench start &> bench_run_logs.txt &
bench start &>> ~/frappe-bench/bench_start.log &
CI=Yes bench build --app frappe &
bench --site test_site reinstall --yes

bench get-app hrms "${GITHUB_WORKSPACE}"
bench --site test_site install-app hrms
bench setup requirements --dev
bench --verbose --site test_site install-app hrms
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import add_days, cint, date_diff, format_date, getdate
from frappe.utils import add_days, cint, date_diff, format_date, get_url_to_list, getdate

from hrms.hr.utils import (
create_additional_leave_ledger_entry,
Expand Down Expand Up @@ -75,7 +75,9 @@ def on_submit(self):
date_difference = date_diff(self.work_end_date, self.work_from_date) + 1
if self.half_day:
date_difference -= 0.5
leave_period = get_leave_period(self.work_from_date, self.work_end_date, company)

comp_leave_valid_from = add_days(self.work_end_date, 1)
leave_period = get_leave_period(comp_leave_valid_from, comp_leave_valid_from, company)
if leave_period:
leave_allocation = self.get_existing_allocation_for_period(leave_period)
if leave_allocation:
Expand All @@ -85,19 +87,22 @@ def on_submit(self):
leave_allocation.db_set("total_leaves_allocated", leave_allocation.total_leaves_allocated)

# generate additional ledger entry for the new compensatory leaves off
create_additional_leave_ledger_entry(
leave_allocation, date_difference, add_days(self.work_end_date, 1)
)
create_additional_leave_ledger_entry(leave_allocation, date_difference, comp_leave_valid_from)

else:
leave_allocation = self.create_leave_allocation(leave_period, date_difference)
self.db_set("leave_allocation", leave_allocation.name)
else:
frappe.throw(
_("There is no leave period in between {0} and {1}").format(
format_date(self.work_from_date), format_date(self.work_end_date)
)
comp_leave_valid_from = frappe.bold(format_date(comp_leave_valid_from))
msg = _("This compensatory leave will be applicable from {0}.").format(comp_leave_valid_from)
msg += " " + _(
"Currently, there is no {0} leave period for this date to create/update leave allocation."
).format(frappe.bold(_("active")))
msg += "<br><br>" + _("Please create a new {0} for the date {1} first.").format(
f"""<a href='{get_url_to_list("Leave Period")}'>Leave Period</a>""",
comp_leave_valid_from,
)
frappe.throw(msg, title=_("No Leave Period Found"))

def on_cancel(self):
if self.leave_allocation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from hrms.hr.doctype.attendance_request.test_attendance_request import get_employee
from hrms.hr.doctype.leave_application.leave_application import get_leave_balance_on
from hrms.hr.doctype.leave_period.test_leave_period import create_leave_period
from hrms.tests.test_utils import add_date_to_holiday_list

test_dependencies = ["Employee"]

Expand Down Expand Up @@ -128,6 +129,31 @@ def test_half_day_compensatory_leave(self):

self.assertEqual(leave_ledger_entry[0].leaves, 0.5)

def test_request_on_leave_period_boundary(self):
frappe.db.delete("Leave Period")
create_leave_period("2023-01-01", "2023-12-31", "_Test Company")

employee = get_employee()
boundary_date = "2023-12-31"
add_date_to_holiday_list(boundary_date, employee.holiday_list)
mark_attendance(employee, boundary_date, "Present")

# no leave period found of "2024-01-01"
compensatory_leave_request = frappe.new_doc("Compensatory Leave Request")
compensatory_leave_request.update(
dict(
employee=employee.name,
leave_type="Compensatory Off",
work_from_date=boundary_date,
work_end_date=boundary_date,
reason="test",
)
)
self.assertRaises(frappe.ValidationError, compensatory_leave_request.submit)

create_leave_period("2023-01-01", "2023-12-31", "_Test Company")
compensatory_leave_request.submit()


def get_compensatory_leave_request(employee, leave_date=today()):
prev_comp_leave_req = frappe.db.get_value(
Expand Down Expand Up @@ -155,7 +181,10 @@ def get_compensatory_leave_request(employee, leave_date=today()):
).insert()


def mark_attendance(employee, date=today(), status="Present"):
def mark_attendance(employee, date=None, status="Present"):
if not date:
date = today()

if not frappe.db.exists(
dict(doctype="Attendance", employee=employee.name, attendance_date=date, status="Present")
):
Expand Down
47 changes: 29 additions & 18 deletions hrms/hr/doctype/shift_assignment/shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,19 +159,21 @@ def get_events(start, end, filters=None):
employee = ""
company = frappe.db.get_value("Global Defaults", None, "default_company")

events = add_assignments(start, end, filters)
return events
assignments = get_shift_assignments(start, end, filters)
return get_shift_events(assignments)


def add_assignments(start, end, filters):
def get_shift_assignments(start: str, end: str, filters: str | list | None = None) -> list[dict]:
import json

events = []
if isinstance(filters, str):
filters = json.loads(filters)
if not filters:
filters = []

filters.extend([["start_date", ">=", start], ["end_date", "<=", end], ["docstatus", "=", 1]])

records = frappe.get_list(
return frappe.get_list(
"Shift Assignment",
filters=filters,
fields=[
Expand All @@ -185,21 +187,28 @@ def add_assignments(start, end, filters):
],
)

shift_timing_map = get_shift_type_timing([d.shift_type for d in records])

for d in records:
def get_shift_events(assignments: list[dict]) -> list[dict]:
events = []
shift_timing_map = get_shift_type_timing([d.shift_type for d in assignments])

for d in assignments:
daily_event_start = d.start_date
daily_event_end = d.end_date if d.end_date else getdate()
daily_event_end = d.end_date or getdate()
shift_start = shift_timing_map[d.shift_type]["start_time"]
shift_end = shift_timing_map[d.shift_type]["end_time"]

delta = timedelta(days=1)
while daily_event_start <= daily_event_end:
start_timing = (
frappe.utils.get_datetime(daily_event_start) + shift_timing_map[d.shift_type]["start_time"]
)
end_timing = (
frappe.utils.get_datetime(daily_event_start) + shift_timing_map[d.shift_type]["end_time"]
)
daily_event_start += delta
e = {
start_timing = frappe.utils.get_datetime(daily_event_start) + shift_start

if shift_start > shift_end:
# shift spans across 2 days
end_timing = frappe.utils.get_datetime(daily_event_start) + shift_end + delta
else:
end_timing = frappe.utils.get_datetime(daily_event_start) + shift_end

event = {
"name": d.name,
"doctype": "Shift Assignment",
"start_date": start_timing,
Expand All @@ -209,8 +218,10 @@ def add_assignments(start, end, filters):
"allDay": 0,
"convertToUserTz": 0,
}
if e not in events:
events.append(e)
if event not in events:
events.append(event)

daily_event_start += delta

return events

Expand Down
13 changes: 12 additions & 1 deletion hrms/hr/doctype/shift_assignment/test_shift_assignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def test_multiple_shift_assignments_for_same_day(self):
date = getdate()
make_shift_assignment(shift_type.name, employee, date)

def test_shift_assignment_calendar(self):
def test_calendar(self):
employee1 = make_employee("[email protected]", company="_Test Company")
employee2 = make_employee("[email protected]", company="_Test Company")

Expand All @@ -242,6 +242,17 @@ def test_shift_assignment_calendar(self):
self.assertEqual(len(events), 1)
self.assertEqual(events[0]["name"], shift1.name)

def test_calendar_for_night_shift(self):
employee1 = make_employee("[email protected]", company="_Test Company")

shift_type = setup_shift_type(shift_type="Shift 1", start_time="08:00:00", end_time="02:00:00")
date = getdate()
shift = make_shift_assignment(shift_type.name, employee1, date, date)

events = get_events(start=date, end=date)
self.assertEqual(events[0]["start_date"], get_datetime(f"{date} 08:00:00"))
self.assertEqual(events[0]["end_date"], get_datetime(f"{add_days(date, 1)} 02:00:00"))

def test_consecutive_day_and_night_shifts(self):
# defaults
employee = make_employee("[email protected]", company="_Test Company")
Expand Down
16 changes: 1 addition & 15 deletions hrms/hr/doctype/shift_type/test_shift_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from hrms.hr.doctype.leave_application.test_leave_application import get_first_sunday
from hrms.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list
from hrms.tests.test_utils import add_date_to_holiday_list


class TestShiftType(FrappeTestCase):
Expand Down Expand Up @@ -648,18 +649,3 @@ def make_shift_assignment(shift_type, employee, start_date, end_date=None, do_no
shift_assignment.submit()

return shift_assignment


def add_date_to_holiday_list(date: str, holiday_list: str) -> None:
if frappe.db.exists("Holiday", {"parent": holiday_list, "holiday_date": date}):
return

holiday_list = frappe.get_doc("Holiday List", holiday_list)
holiday_list.append(
"holidays",
{
"holiday_date": date,
"description": "test",
},
)
holiday_list.save()
8 changes: 4 additions & 4 deletions hrms/hr/hr_dashboard/human_resource/human_resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"card": "Employee Exits (This Year)"
},
{
"card": "Employees Joining (Next Quarter)"
"card": "Employees Joining (This Quarter)"
},
{
"card": "Employees Relieving (Next Quarter)"
"card": "Employees Relieving (This Quarter)"
}
],
"charts": [
Expand Down Expand Up @@ -50,14 +50,14 @@
"width": "Half"
}
],
"creation": "2020-07-22 11:56:33.015888",
"creation": "2023-11-17 14:10:56.741833",
"dashboard_name": "Human Resource",
"docstatus": 0,
"doctype": "Dashboard",
"idx": 0,
"is_default": 0,
"is_standard": 1,
"modified": "2022-08-22 19:10:33.594097",
"modified": "2024-01-08 14:06:32.104261",
"modified_by": "Administrator",
"module": "HR",
"name": "Human Resource",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
{
"aggregate_function_based_on": "",
"creation": "2022-08-22 12:25:05.129659",
"creation": "2023-11-17 14:10:57.027579",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Employee",
"dynamic_filters_json": "[[\"Employee\",\"company\",\"=\",\"frappe.defaults.get_user_default(\\\"Company\\\")\"]]",
"filters_json": "[[\"Employee\",\"date_of_joining\",\"Timespan\",\"next quarter\",false]]",
"filters_json": "[[\"Employee\",\"date_of_joining\",\"Timespan\",\"this quarter\",false]]",
"function": "Count",
"idx": 0,
"is_public": 1,
"is_standard": 1,
"label": "Employees Joining (Next Quarter)",
"modified": "2022-08-22 12:25:13.302161",
"label": "Employees Joining (This Quarter)",
"modified": "2024-01-08 13:55:24.783641",
"modified_by": "Administrator",
"module": "HR",
"name": "Employees Joining (Next Quarter)",
"name": "Employees Joining (This Quarter)",
"owner": "Administrator",
"parent_document_type": "",
"report_function": "Sum",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"aggregate_function_based_on": "",
"creation": "2022-08-22 12:25:36.324395",
"creation": "2023-11-17 14:10:57.129602",
"docstatus": 0,
"doctype": "Number Card",
"document_type": "Employee",
Expand All @@ -10,11 +10,11 @@
"idx": 0,
"is_public": 1,
"is_standard": 1,
"label": "Employees Relieving (Next Quarter)",
"modified": "2022-08-22 12:26:42.672235",
"label": "Employees Relieving (This Quarter)",
"modified": "2024-01-08 13:53:21.245802",
"modified_by": "Administrator",
"module": "HR",
"name": "Employees Relieving (Next Quarter)",
"name": "Employees Relieving (This Quarter)",
"owner": "Administrator",
"parent_document_type": "",
"report_function": "Sum",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,15 @@ frappe.query_reports["Employee Leave Balance"] = {
depends_on: "eval: !doc.employee",
}
],

onload: () => {
const today = frappe.datetime.now_date();

frappe.call({
type: "GET",
method: "hrms.hr.utils.get_leave_period",
args: {
"from_date": frappe.defaults.get_default("year_start_date"),
"to_date": frappe.defaults.get_default("year_end_date"),
"from_date": today,
"to_date": today,
"company": frappe.defaults.get_user_default("Company")
},
freeze: true,
Expand Down
Loading

0 comments on commit 5124c0e

Please sign in to comment.