mirror of
https://github.com/frappe/erpnext.git
synced 2026-10-29 22:57:42 +00:00
fix(setup): reject duplicate holiday dates across value types
Normalize holiday dates before duplicate validation so a date loaded from the database and a string appended by server code compare equal. Add a saved-list regression test that checks failed saves leave one holiday row.
Issue: frappe/erpnext-bug-reviews#386 (bug 1)
(cherry picked from commit 4e596af1d5)
This commit is contained in:
committed by
Mergify
parent
ed59ce64f3
commit
dcb85b56c6
@@ -147,15 +147,13 @@ class HolidayList(Document):
|
||||
|
||||
def validate_duplicate_date(self):
|
||||
unique_dates = []
|
||||
for row in self.holidays:
|
||||
if row.holiday_date in unique_dates:
|
||||
for holiday_date in self.get_holidays():
|
||||
if holiday_date in unique_dates:
|
||||
frappe.throw(
|
||||
_("Holiday Date {0} added multiple times").format(
|
||||
frappe.bold(formatdate(row.holiday_date))
|
||||
)
|
||||
_("Holiday Date {0} added multiple times").format(frappe.bold(formatdate(holiday_date)))
|
||||
)
|
||||
|
||||
unique_dates.append(row.holiday_date)
|
||||
unique_dates.append(holiday_date)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
|
||||
@@ -25,6 +25,24 @@ class TestHolidayList(unittest.TestCase):
|
||||
fetched_holiday_list = frappe.get_value("Holiday List", holiday_list.name)
|
||||
self.assertEqual(holiday_list.name, fetched_holiday_list)
|
||||
|
||||
def test_duplicate_date_on_saved_list_with_string_date(self):
|
||||
holiday_list = make_holiday_list(
|
||||
"test_duplicate_holiday_date",
|
||||
from_date="2031-01-01",
|
||||
to_date="2031-12-31",
|
||||
holiday_dates=[{"holiday_date": "2031-03-03", "description": "Original"}],
|
||||
)
|
||||
holiday_list = frappe.get_doc("Holiday List", holiday_list.name)
|
||||
self.assertEqual(holiday_list.holidays[0].holiday_date, date(2031, 3, 3))
|
||||
holiday_list.append("holidays", {"holiday_date": "2031-03-03", "description": "Duplicate"})
|
||||
|
||||
with self.assertRaises(frappe.ValidationError):
|
||||
holiday_list.save()
|
||||
|
||||
self.assertEqual(
|
||||
frappe.db.count("Holiday", {"parent": holiday_list.name, "holiday_date": "2031-03-03"}), 1
|
||||
)
|
||||
|
||||
def test_weekly_off(self):
|
||||
holiday_list = frappe.new_doc("Holiday List")
|
||||
holiday_list.from_date = "2023-01-01"
|
||||
|
||||
Reference in New Issue
Block a user