fix(Project): get correct holiday list when calculating dates; test fixes (#24901)
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index 8ba0b6c..f9e1359 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -81,12 +81,18 @@
def calculate_start_date(self, task_details):
self.start_date = add_days(self.expected_start_date, task_details.start)
- self.start_date = update_if_holiday(self.holiday_list, self.start_date)
+ self.start_date = self.update_if_holiday(self.start_date)
return self.start_date
def calculate_end_date(self, task_details):
self.end_date = add_days(self.start_date, task_details.duration)
- return update_if_holiday(self.holiday_list, self.end_date)
+ return self.update_if_holiday(self.end_date)
+
+ def update_if_holiday(self, date):
+ holiday_list = self.holiday_list or get_holiday_list(self.company)
+ while is_holiday(holiday_list, date):
+ date = add_days(date, 1)
+ return date
def dependency_mapping(self, template_tasks, project_tasks):
for template_task in template_tasks:
@@ -541,9 +547,3 @@
project.status = status
project.save()
-
-def update_if_holiday(holiday_list, date):
- holiday_list = holiday_list or get_holiday_list()
- while is_holiday(holiday_list, date):
- date = add_days(date, 1)
- return date
diff --git a/erpnext/projects/doctype/project/test_project.py b/erpnext/projects/doctype/project/test_project.py
index 6290538..15a2873 100644
--- a/erpnext/projects/doctype/project/test_project.py
+++ b/erpnext/projects/doctype/project/test_project.py
@@ -8,7 +8,6 @@
test_ignore = ["Sales Order"]
from erpnext.projects.doctype.project_template.test_project_template import make_project_template
-from erpnext.projects.doctype.project.project import update_if_holiday
from erpnext.projects.doctype.task.test_task import create_task
from frappe.utils import getdate, nowdate, add_days
@@ -97,7 +96,8 @@
project_name = name,
status = 'Open',
project_template = template.name,
- expected_start_date = nowdate()
+ expected_start_date = nowdate(),
+ company="_Test Company"
)).insert()
return project
@@ -131,7 +131,7 @@
def calculate_end_date(project, start, duration):
start = add_days(project.expected_start_date, start)
- start = update_if_holiday(project.holiday_list, start)
+ start = project.update_if_holiday(start)
end = add_days(start, duration)
- end = update_if_holiday(project.holiday_list, end)
- return getdate(end)
\ No newline at end of file
+ end = project.update_if_holiday(end)
+ return getdate(end)