update calendar functionality and holidays

This commit is contained in:
Casey 2026-01-20 17:06:28 -06:00
parent 0620060066
commit 7395d3e048
9 changed files with 859 additions and 440 deletions

View file

@ -4,6 +4,8 @@ import subprocess
import sys
import frappe
from .utils import create_module
import holidays
from datetime import date, timedelta
def after_install():
create_module()
@ -29,6 +31,8 @@ def after_migrate():
for doctype in doctypes_to_refresh:
frappe.clear_cache(doctype=doctype)
frappe.reload_doctype(doctype)
check_and_create_holiday_list()
# update_address_fields()
# build_frontend()
@ -951,4 +955,54 @@ def build_missing_field_specs(custom_fields, missing_fields):
missing_field_specs[doctype].append(field_spec)
break
return missing_field_specs
return missing_field_specs
def check_and_create_holiday_list(year=2026, country="US", weekly_off="Sunday"):
"""Check if Holiday List for the given year exists, if not create it."""
print(f"\n🔧 Checking for Holiday List for {country} in {year}...")
holiday_list_name = f"{country} Holidays {year}"
if frappe.db.exists("Holiday List", holiday_list_name):
print(f"✅ Holiday List '{holiday_list_name}' already exists.")
return
else:
print(f"❌ Holiday List '{holiday_list_name}' does not exist. Creating...")
us_holidays = holidays.US(years=[year])
sundays = get_all_sundays(year)
hl = frappe.get_doc({
"doctype": "Holiday List",
"holiday_list_name": holiday_list_name,
"country": country,
"year": year,
"from_date": f"{year}-01-01",
"to_date": f"{year}-12-31",
"weekly_off": weekly_off,
"holidays": [
{
"holiday_date": holiday_date,
"description": holiday_name
} for holiday_date, holiday_name in us_holidays.items()
]
})
for sunday in sundays:
hl.append("holidays", {
"holiday_date": sunday,
"description": "Sunday"
})
hl.insert()
# hl.make_holiday_entries()
frappe.db.commit()
print(f"✅ Holiday List '{holiday_list_name}' created successfully.")
def get_all_sundays(year):
sundays = []
d = date(year, 1, 1)
while d.weekday() != 6:
d += timedelta(days=1)
while d.year == year:
sundays.append(d)
d += timedelta(days=7)
return sundays