From bf57585e3e64ceefe8620a114fa7209566e30164 Mon Sep 17 00:00:00 2001 From: Vikas Agarwal Date: Tue, 21 Aug 2018 11:00:37 +0530 Subject: [PATCH] =?UTF-8?q?Github=20issue#2398,=20Impossible=20to=20add=20?= =?UTF-8?q?phases=20to=20older=20project=20=E2=80=94=20Fixed?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/projects/actions/project.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/projects/actions/project.js b/src/projects/actions/project.js index 886dcfcad..7f78ed1cb 100644 --- a/src/projects/actions/project.js +++ b/src/projects/actions/project.js @@ -280,14 +280,18 @@ export function createProduct(project, productTemplate, phases, timelines) { const lastMilestone = _.maxBy(timelineState.timeline.milestones, 'order') // calculates the start date for the new phase by adding 1 day to the end date of the milestone // we don't use end date field of milestone because it might not reflect the correct end date - startDate = moment(lastMilestone.startDate).hours(0).minutes(0).seconds(0) - .milliseconds(0).add(lastMilestone.duration - 1, 'days').add(1, 'days') - } else { + if (lastMilestone && lastMilestone.startDate) { + startDate = moment(lastMilestone.startDate).hours(0).minutes(0).seconds(0) + .milliseconds(0).add(lastMilestone.duration - 1, 'days').add(1, 'days') + } + } else if (phase.startDate) { // if there is no timeline for the phase, calculates the next phase's start date by adding 1 day to the // end date of last phase, we don't use end date field of milestone because it might not reflect the // correct end date startDate = moment(phase.startDate).hours(0).minutes(0).seconds(0) .milliseconds(0).add(phase.duration - 1, 'days').add(1, 'days') + } else { + // do nothing, use today as start date } } // assumes 10 days as default duration, ideally we could store it at template level