Merge pull request #39327 from frappe/mergify/bp/version-15-hotfix/pr-39117

fix: consider all years in holiday list (backport #39117)
This commit is contained in:
Raffael Meyer 2024-01-11 15:04:29 +01:00 committed by GitHub
commit 6f06313023
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 6 deletions

View File

@ -87,7 +87,7 @@ class HolidayList(Document):
for holiday_date, holiday_name in country_holidays(
self.country,
subdiv=self.subdivision,
years=[from_date.year, to_date.year],
years=list(range(from_date.year, to_date.year + 1)),
language=frappe.local.lang,
).items():
if holiday_date in existing_holidays:

View File

@ -48,17 +48,58 @@ class TestHolidayList(unittest.TestCase):
def test_local_holidays(self):
holiday_list = frappe.new_doc("Holiday List")
holiday_list.from_date = "2023-04-01"
holiday_list.to_date = "2023-04-30"
holiday_list.from_date = "2022-01-01"
holiday_list.to_date = "2024-12-31"
holiday_list.country = "DE"
holiday_list.subdivision = "SN"
holiday_list.get_local_holidays()
holidays = [holiday.holiday_date for holiday in holiday_list.holidays]
self.assertNotIn(date(2023, 1, 1), holidays)
holidays = holiday_list.get_holidays()
self.assertIn(date(2022, 1, 1), holidays)
self.assertIn(date(2022, 4, 15), holidays)
self.assertIn(date(2022, 4, 18), holidays)
self.assertIn(date(2022, 5, 1), holidays)
self.assertIn(date(2022, 5, 26), holidays)
self.assertIn(date(2022, 6, 6), holidays)
self.assertIn(date(2022, 10, 3), holidays)
self.assertIn(date(2022, 10, 31), holidays)
self.assertIn(date(2022, 11, 16), holidays)
self.assertIn(date(2022, 12, 25), holidays)
self.assertIn(date(2022, 12, 26), holidays)
self.assertIn(date(2023, 1, 1), holidays)
self.assertIn(date(2023, 4, 7), holidays)
self.assertIn(date(2023, 4, 10), holidays)
self.assertNotIn(date(2023, 5, 1), holidays)
self.assertIn(date(2023, 5, 1), holidays)
self.assertIn(date(2023, 5, 18), holidays)
self.assertIn(date(2023, 5, 29), holidays)
self.assertIn(date(2023, 10, 3), holidays)
self.assertIn(date(2023, 10, 31), holidays)
self.assertIn(date(2023, 11, 22), holidays)
self.assertIn(date(2023, 12, 25), holidays)
self.assertIn(date(2023, 12, 26), holidays)
self.assertIn(date(2024, 1, 1), holidays)
self.assertIn(date(2024, 3, 29), holidays)
self.assertIn(date(2024, 4, 1), holidays)
self.assertIn(date(2024, 5, 1), holidays)
self.assertIn(date(2024, 5, 9), holidays)
self.assertIn(date(2024, 5, 20), holidays)
self.assertIn(date(2024, 10, 3), holidays)
self.assertIn(date(2024, 10, 31), holidays)
self.assertIn(date(2024, 11, 20), holidays)
self.assertIn(date(2024, 12, 25), holidays)
self.assertIn(date(2024, 12, 26), holidays)
# check some random dates that should not be local holidays
self.assertNotIn(date(2022, 1, 2), holidays)
self.assertNotIn(date(2023, 4, 16), holidays)
self.assertNotIn(date(2024, 4, 19), holidays)
self.assertNotIn(date(2022, 5, 2), holidays)
self.assertNotIn(date(2023, 5, 27), holidays)
self.assertNotIn(date(2024, 6, 7), holidays)
self.assertNotIn(date(2022, 10, 4), holidays)
self.assertNotIn(date(2023, 10, 30), holidays)
self.assertNotIn(date(2024, 11, 17), holidays)
self.assertNotIn(date(2022, 12, 24), holidays)
def test_localized_country_names(self):
lang = frappe.local.lang