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

feat(poc): holiday assignment #2768

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
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: 2 additions & 0 deletions hrms/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,3 +362,5 @@
"Employee Onboarding Template",
"Employee Separation Template",
]

employee_holiday_list = "hrms.utils.holiday_list.get_holiday_list_for_employee"
Empty file.
8 changes: 8 additions & 0 deletions hrms/hr/doctype/holiday_assignment/holiday_assignment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
// For license information, please see license.txt

// frappe.ui.form.on("Holiday Assignment", {
// refresh(frm) {

// },
// });
109 changes: 109 additions & 0 deletions hrms/hr/doctype/holiday_assignment/holiday_assignment.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"actions": [],
"autoname": "HR-HLDY-ASSGN-.#####",
"creation": "2025-02-08 18:39:56.893204",
"doctype": "DocType",
"engine": "InnoDB",
"field_order": [
"section_break_tpjs",
"employee",
"employee_name",
"holiday_list",
"column_break_agfv",
"company",
"from_date",
"to_date",
"amended_from"
],
"fields": [
{
"fieldname": "section_break_tpjs",
"fieldtype": "Section Break"
},
{
"fieldname": "amended_from",
"fieldtype": "Link",
"label": "Amended From",
"no_copy": 1,
"options": "Holiday Assignment",
"print_hide": 1,
"read_only": 1,
"search_index": 1
},
{
"fieldname": "employee",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Employee",
"options": "Employee",
"reqd": 1
},
{
"fieldname": "column_break_agfv",
"fieldtype": "Column Break"
},
{
"fieldname": "company",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Company",
"options": "Company",
"reqd": 1
},
{
"fetch_from": "employee.employee",
"fieldname": "employee_name",
"fieldtype": "Data",
"label": "Employee Name",
"read_only": 1
},
{
"fieldname": "holiday_list",
"fieldtype": "Link",
"label": "Holiday List",
"options": "Holiday List",
"reqd": 1
},
{
"fieldname": "from_date",
"fieldtype": "Date",
"in_list_view": 1,
"label": "From Date",
"reqd": 1
},
{
"fieldname": "to_date",
"fieldtype": "Date",
"in_list_view": 1,
"label": "To Date",
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"is_submittable": 1,
"links": [],
"modified": "2025-02-08 19:03:56.208781",
"modified_by": "Administrator",
"module": "HR",
"name": "Holiday Assignment",
"naming_rule": "Expression (old style)",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"submit": 1,
"write": 1
}
],
"sort_field": "creation",
"sort_order": "DESC",
"states": []
}
9 changes: 9 additions & 0 deletions hrms/hr/doctype/holiday_assignment/holiday_assignment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt

# import frappe
from frappe.model.document import Document


class HolidayAssignment(Document):
pass
30 changes: 30 additions & 0 deletions hrms/hr/doctype/holiday_assignment/test_holiday_assignment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2025, Frappe Technologies Pvt. Ltd. and Contributors
# See license.txt

# import frappe
from frappe.tests import IntegrationTestCase, UnitTestCase


# On IntegrationTestCase, the doctype test records and all
# link-field test record dependencies are recursively loaded
# Use these module variables to add/remove to/from that list
EXTRA_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]
IGNORE_TEST_RECORD_DEPENDENCIES = [] # eg. ["User"]


class UnitTestHolidayAssignment(UnitTestCase):
"""
Unit tests for HolidayAssignment.
Use this class for testing individual functions and methods.
"""

pass


class IntegrationTestHolidayAssignment(IntegrationTestCase):
"""
Integration tests for HolidayAssignment.
Use this class for testing interactions between multiple components.
"""

pass
27 changes: 27 additions & 0 deletions hrms/utils/holiday_list.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import frappe
from frappe import _


def get_holiday_dates_between(
Expand All @@ -25,3 +26,29 @@ def invalidate_cache(doc, method=None):
from hrms.payroll.doctype.salary_slip.salary_slip import HOLIDAYS_BETWEEN_DATES

frappe.cache().delete_value(HOLIDAYS_BETWEEN_DATES)


def get_holiday_list_for_employee(
employee: str,
raise_exception: bool = True,
as_on=None
) -> str:
as_on = frappe.utils.getdate(as_on)
HolidayList = frappe.qb.DocType("Holiday Assignment")
query = (
frappe.qb.from_(HolidayList)
.select(HolidayList.holiday_list)
.where(HolidayList.employee == employee)
.where(HolidayList.from_date <= as_on)
.where(HolidayList.to_date >= as_on)
.where(HolidayList.docstatus == 1)
.run()
)
holiday_list = query[0][0] if query else None

if not holiday_list and raise_exception:
frappe.throw(
_("Please assign Holiday List for Employee {0}").format(employee)
)

return holiday_list
Loading