diff --git a/base/models.py b/base/models.py
index dbd896330..5774a1883 100644
--- a/base/models.py
+++ b/base/models.py
@@ -1647,6 +1647,20 @@ class Holidays(HorillaModel):
def __str__(self):
return self.name
+ def today_holidays(today=None) -> models.QuerySet:
+ """
+ Retrieve holidays that overlap with the given date (default is today).
+
+ Args:
+ today (date, optional): The date to check for holidays. Defaults to the current date.
+
+ Returns:
+ QuerySet: A queryset of `Holidays` instances where the given date falls between
+ `start_date` and `end_date` (inclusive).
+ """
+ today = today or date.today()
+ return Holidays.objects.filter(start_date__lte=today, end_date__gte=today)
+
class CompanyLeaves(HorillaModel):
based_on_week = models.CharField(
diff --git a/base/templates/holiday/upcoming_holidays.html b/base/templates/holiday/upcoming_holidays.html
new file mode 100644
index 000000000..0bb7549cf
--- /dev/null
+++ b/base/templates/holiday/upcoming_holidays.html
@@ -0,0 +1,23 @@
+{% load static %}
+{% load i18n %}
+
\ No newline at end of file
diff --git a/base/urls.py b/base/urls.py
index d4774579c..422f392fd 100644
--- a/base/urls.py
+++ b/base/urls.py
@@ -995,6 +995,11 @@ urlpatterns = [
"holidays-info-import", views.holidays_info_import, name="holidays-info-import"
),
path("holiday-info-export", views.holiday_info_export, name="holiday-info-export"),
+ path(
+ "get-upcoming-holidays",
+ views.get_upcoming_holidays,
+ name="get-upcoming-holidays",
+ ),
path("holiday-creation", views.holiday_creation, name="holiday-creation"),
path("holiday-update/", views.holiday_update, name="holiday-update"),
path("holiday-delete/", views.holiday_delete, name="holiday-delete"),
diff --git a/base/views.py b/base/views.py
index 0c0885d76..e9e549cbf 100644
--- a/base/views.py
+++ b/base/views.py
@@ -32,6 +32,7 @@ from django.template.loader import render_to_string
from django.urls import reverse, reverse_lazy
from django.utils import timezone
from django.utils.html import strip_tags
+from django.utils.timezone import localdate
from django.utils.translation import gettext as _
from django.views.decorators.csrf import csrf_exempt
from django.views.decorators.http import require_http_methods
@@ -107,10 +108,12 @@ from base.methods import (
filtersubordinates,
filtersubordinatesemployeemodel,
format_date,
+ generate_colors,
get_key_instances,
get_pagination,
is_reportingmanager,
paginator_qry,
+ random_color_generator,
sortby,
)
from base.models import (
@@ -6501,6 +6504,25 @@ def generate_error_report(error_list, error_data, file_name):
return path_info
+@login_required
+@hx_request_required
+def get_upcoming_holidays(request):
+ """
+ Retrieve and display a list of upcoming holidays for the current month and year.
+ """
+ today = localdate() # This accounts for timezone-aware dates
+ current_month = today.month
+ current_year = today.year
+ holidays = Holidays.objects.filter(
+ Q(start_date__month=current_month, start_date__year=current_year)
+ & Q(start_date__gte=today)
+ )
+ colors = generate_colors(len(holidays))
+ for i, holiday in enumerate(holidays):
+ holiday.background_color = colors[i]
+ return render(request, "holiday/upcoming_holidays.html", {"holidays": holidays})
+
+
@login_required
@hx_request_required
@permission_required("base.add_holidays")