feat: aholiday check before setting start and end date in task
This commit is contained in:
parent
3a26f26671
commit
4ebee5014e
@ -13,6 +13,7 @@ from frappe.desk.reportview import get_match_cond
|
|||||||
from erpnext.hr.doctype.daily_work_summary.daily_work_summary import get_users_email
|
from erpnext.hr.doctype.daily_work_summary.daily_work_summary import get_users_email
|
||||||
from erpnext.hr.doctype.holiday_list.holiday_list import is_holiday
|
from erpnext.hr.doctype.holiday_list.holiday_list import is_holiday
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from erpnext.education.doctype.student_attendance.student_attendance import get_holiday_list
|
||||||
|
|
||||||
class Project(Document):
|
class Project(Document):
|
||||||
def get_feed(self):
|
def get_feed(self):
|
||||||
@ -69,8 +70,8 @@ class Project(Document):
|
|||||||
subject = task_details.subject,
|
subject = task_details.subject,
|
||||||
project = self.name,
|
project = self.name,
|
||||||
status = 'Open',
|
status = 'Open',
|
||||||
exp_start_date = add_days(self.expected_start_date, task_details.start),
|
exp_start_date = self.calculate_start_date(task_details),
|
||||||
exp_end_date = add_days(self.expected_start_date, task_details.start + task_details.duration),
|
exp_end_date = self.calculate_end_date(task_details),
|
||||||
description = task_details.description,
|
description = task_details.description,
|
||||||
task_weight = task_details.task_weight,
|
task_weight = task_details.task_weight,
|
||||||
type = task_details.type,
|
type = task_details.type,
|
||||||
@ -78,6 +79,21 @@ class Project(Document):
|
|||||||
is_group = task_details.is_group
|
is_group = task_details.is_group
|
||||||
)).insert()
|
)).insert()
|
||||||
|
|
||||||
|
def calculate_start_date(self, task_details):
|
||||||
|
self.start_date = add_days(self.expected_start_date, task_details.start)
|
||||||
|
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 self.update_if_holiday(self.end_date)
|
||||||
|
|
||||||
|
def update_if_holiday(self, date):
|
||||||
|
holiday_list = self.holiday_list or get_holiday_list()
|
||||||
|
while is_holiday(holiday_list, date):
|
||||||
|
date = add_days(date, 1)
|
||||||
|
return date
|
||||||
|
|
||||||
def dependency_mapping(self, template_tasks, project_tasks):
|
def dependency_mapping(self, template_tasks, project_tasks):
|
||||||
for template_task in template_tasks:
|
for template_task in template_tasks:
|
||||||
project_task = list(filter(lambda x: x.subject == template_task.subject, project_tasks))[0]
|
project_task = list(filter(lambda x: x.subject == template_task.subject, project_tasks))[0]
|
||||||
|
@ -14,9 +14,6 @@ from frappe.utils import getdate, nowdate, add_days
|
|||||||
|
|
||||||
class TestProject(unittest.TestCase):
|
class TestProject(unittest.TestCase):
|
||||||
def test_project_with_template_having_no_parent_and_depend_tasks(self):
|
def test_project_with_template_having_no_parent_and_depend_tasks(self):
|
||||||
"""
|
|
||||||
Test Action: Basic Test of a Project created from template. The template has a single task.
|
|
||||||
"""
|
|
||||||
project_name = "Test Project with Template - No Parent and Dependend Tasks"
|
project_name = "Test Project with Template - No Parent and Dependend Tasks"
|
||||||
frappe.db.sql(""" delete from tabTask where project = %s """, project_name)
|
frappe.db.sql(""" delete from tabTask where project = %s """, project_name)
|
||||||
frappe.delete_doc('Project', project_name)
|
frappe.delete_doc('Project', project_name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user