Skip to content

Commit

Permalink
Merge pull request #1645 from frappe/version-14-hotfix
Browse files Browse the repository at this point in the history
chore: release v14
  • Loading branch information
ruchamahabal authored Apr 10, 2024
2 parents 943ec5d + 9365b55 commit a615de6
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 25 deletions.
12 changes: 11 additions & 1 deletion hrms/hr/doctype/attendance/attendance.json
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@
"idx": 1,
"is_submittable": 1,
"links": [],
"modified": "2023-06-15 20:09:21.730465",
"modified": "2024-04-05 20:55:02.905452",
"modified_by": "Administrator",
"module": "HR",
"name": "Attendance",
Expand Down Expand Up @@ -254,6 +254,16 @@
"share": 1,
"submit": 1,
"write": 1
},
{
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Employee",
"select": 1,
"share": 1
}
],
"search_fields": "employee,employee_name,attendance_date,status",
Expand Down
35 changes: 30 additions & 5 deletions hrms/hr/doctype/attendance/attendance.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
)

from hrms.hr.doctype.shift_assignment.shift_assignment import has_overlapping_timings
from hrms.hr.utils import get_holiday_dates_for_employee, validate_active_employee
from hrms.hr.utils import (
get_holiday_dates_for_employee,
get_holidays_for_employee,
validate_active_employee,
)


class DuplicateAttendanceError(frappe.ValidationError):
Expand Down Expand Up @@ -227,25 +231,27 @@ def unlink_attendance_from_checkins(self):

@frappe.whitelist()
def get_events(start, end, filters=None):
from frappe.desk.reportview import get_filters_cond

events = []

employee = frappe.db.get_value("Employee", {"user_id": frappe.session.user})

if not employee:
return events

from frappe.desk.reportview import get_filters_cond

conditions = get_filters_cond("Attendance", filters, [])
add_attendance(events, start, end, conditions=conditions)
add_holidays(events, start, end, employee)
return events


def add_attendance(events, start, end, conditions=None):
query = """select name, attendance_date, status
query = """select name, attendance_date, status, employee_name
from `tabAttendance` where
attendance_date between %(from_date)s and %(to_date)s
and docstatus < 2"""

if conditions:
query += conditions

Expand All @@ -255,13 +261,32 @@ def add_attendance(events, start, end, conditions=None):
"doctype": "Attendance",
"start": d.attendance_date,
"end": d.attendance_date,
"title": cstr(d.status),
"title": f"{d.employee_name}: {cstr(d.status)}",
"status": d.status,
"docstatus": d.docstatus,
}
if e not in events:
events.append(e)


def add_holidays(events, start, end, employee=None):
holidays = get_holidays_for_employee(employee, start, end)
if not holidays:
return

for holiday in holidays:
events.append(
{
"doctype": "Holiday",
"start": holiday.holiday_date,
"end": holiday.holiday_date,
"title": _("Holiday") + ": " + cstr(holiday.description),
"name": holiday.name,
"allDay": 1,
}
)


def mark_attendance(
employee,
attendance_date,
Expand Down
28 changes: 23 additions & 5 deletions hrms/hr/doctype/attendance/attendance_calendar.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
// Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt
frappe.views.calendar["Attendance"] = {
field_map: {
start: "start",
end: "end",
id: "name",
title: "title",
allDay: "allDay",
color: "color",
},
get_css_class: function (data) {
if (data.doctype === "Holiday") return "default";
else if (data.doctype === "Attendance") {
if (data.status === "Absent" || data.status === "On Leave") {
return "danger";
}
if (data.status === "Half Day") return "warning";
return "success";
}
},
options: {
header: {
left: 'prev,next today',
center: 'title',
right: 'month'
}
left: "prev,next today",
center: "title",
right: "month",
},
},
get_events_method: "hrms.hr.doctype.attendance.attendance.get_events"
get_events_method: "hrms.hr.doctype.attendance.attendance.get_events",
};
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def test_half_day_compensatory_leave(self):
def test_request_on_leave_period_boundary(self):
frappe.db.delete("Leave Period")
create_leave_period("2023-01-01", "2023-12-31", "_Test Company")
create_holiday_list("2023-01-01", "2023-12-31")

employee = get_employee()
boundary_date = "2023-12-31"
Expand All @@ -149,9 +150,11 @@ def test_request_on_leave_period_boundary(self):
reason="test",
)
)
compensatory_leave_request.insert()
self.assertRaises(frappe.ValidationError, compensatory_leave_request.submit)

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


Expand Down Expand Up @@ -195,20 +198,27 @@ def mark_attendance(employee, date=None, status="Present"):
attendance.submit()


def create_holiday_list():
if frappe.db.exists("Holiday List", "_Test Compensatory Leave"):
return
def create_holiday_list(from_date=None, to_date=None):
list_name = "_Test Compensatory Leave"
if frappe.db.exists("Holiday List", list_name):
frappe.db.delete("Holiday List", list_name)
frappe.db.delete("Holiday", {"parent": list_name})

if from_date:
holiday_date = add_days(from_date, 1)
else:
holiday_date = today()

holiday_list = frappe.get_doc(
{
"doctype": "Holiday List",
"from_date": add_months(today(), -3),
"to_date": add_months(today(), 3),
"from_date": from_date or add_months(today(), -3),
"to_date": to_date or add_months(today(), 3),
"holidays": [
{"description": "Test Holiday", "holiday_date": today()},
{"description": "Test Holiday 1", "holiday_date": add_days(today(), -1)},
{"description": "Test Holiday", "holiday_date": holiday_date},
{"description": "Test Holiday 1", "holiday_date": add_days(holiday_date, -1)},
],
"holiday_list_name": "_Test Compensatory Leave",
"holiday_list_name": list_name,
}
)
holiday_list.save()
3 changes: 2 additions & 1 deletion hrms/hr/doctype/employee_checkin/employee_checkin.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
{
"fieldname": "employee",
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Employee",
"options": "Employee",
"reqd": 1,
Expand Down Expand Up @@ -109,7 +110,7 @@
}
],
"links": [],
"modified": "2023-05-12 14:52:22.660264",
"modified": "2024-04-02 01:50:23.150627",
"modified_by": "Administrator",
"module": "HR",
"name": "Employee Checkin",
Expand Down
4 changes: 3 additions & 1 deletion hrms/hr/doctype/shift_assignment/shift_assignment.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
{
"fieldname": "employee",
"fieldtype": "Link",
"in_standard_filter": 1,
"label": "Employee",
"options": "Employee",
"reqd": 1,
Expand All @@ -47,6 +48,7 @@
"fieldname": "shift_type",
"fieldtype": "Link",
"in_list_view": 1,
"in_standard_filter": 1,
"label": "Shift Type",
"options": "Shift Type",
"reqd": 1,
Expand Down Expand Up @@ -103,7 +105,7 @@
],
"is_submittable": 1,
"links": [],
"modified": "2023-06-23 12:08:23.247882",
"modified": "2024-04-04 17:13:13.137431",
"modified_by": "Administrator",
"module": "HR",
"name": "Shift Assignment",
Expand Down
10 changes: 7 additions & 3 deletions hrms/overrides/employee_payment_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def set_missing_ref_details(
self,
force: bool = False,
update_ref_details_only_for: list | None = None,
ref_exchange_rate: float | None = None,
reference_exchange_details: dict | None = None,
) -> None:
for d in self.get("references"):
if d.allocated_amount:
Expand All @@ -45,8 +45,12 @@ def set_missing_ref_details(
)

# Only update exchange rate when the reference is Journal Entry
if ref_exchange_rate and d.reference_doctype == "Journal Entry":
ref_details.update({"exchange_rate": ref_exchange_rate})
if (
reference_exchange_details
and d.reference_doctype == reference_exchange_details.reference_doctype
and d.reference_name == reference_exchange_details.reference_name
):
ref_details.update({"exchange_rate": reference_exchange_details.exchange_rate})

for field, value in ref_details.items():
if d.exchange_gain_loss:
Expand Down

0 comments on commit a615de6

Please sign in to comment.