Fix issue: task time tracking is not updated when deleting a subtask

This commit is contained in:
Frederic Guillot 2015-09-14 22:10:08 -04:00
parent eaff957839
commit d1e6c39df4
5 changed files with 24 additions and 25 deletions

View File

@ -26,6 +26,7 @@ Bug fixes:
* Fix typo in template that prevent the Gitlab oauth link to be displayed
* Fix Markdown preview links focus
* Avoid dropdown menu to be truncated inside a column with scrolling
* Deleting subtask doesn't update task time tracking
Version 1.0.18
--------------

View File

@ -339,20 +339,7 @@ class SubtaskTimeTracking extends Base
*/
public function updateTaskTimeTracking($task_id)
{
$result = $this->calculateSubtaskTime($task_id);
$values = array();
if ($result['total_spent'] > 0) {
$values['time_spent'] = $result['total_spent'];
}
if ($result['total_estimated'] > 0) {
$values['time_estimated'] = $result['total_estimated'];
}
if (empty($values)) {
return true;
}
$values = $this->calculateSubtaskTime($task_id);
return $this->db
->table(Task::TABLE)
@ -373,8 +360,8 @@ class SubtaskTimeTracking extends Base
->table(Subtask::TABLE)
->eq('task_id', $task_id)
->columns(
'SUM(time_spent) AS total_spent',
'SUM(time_estimated) AS total_estimated'
'SUM(time_spent) AS time_spent',
'SUM(time_estimated) AS time_estimated'
)
->findOne();
}

View File

@ -12,6 +12,7 @@ class SubtaskTimeTrackingSubscriber extends \Core\Base implements EventSubscribe
{
return array(
Subtask::EVENT_CREATE => array('updateTaskTime', 0),
Subtask::EVENT_DELETE => array('updateTaskTime', 0),
Subtask::EVENT_UPDATE => array(
array('logStartEnd', 10),
array('updateTaskTime', 0),

View File

@ -40,5 +40,5 @@ Subtask timer
- Each time a subtask is in progress, the timer is also started. The timer can be started and stopped at any time.
- The timer records the time spent on the subtask automatically. You can also change manually the value of the time spent field when you edit a subtask.
- The time calculated is rounded to the nearest quarter. This information is recorded in a separate table.
- The task time spent is updated automatically according to the sum of all subtasks time spent.
- The task time spent and time estimated are updated automatically according to the sum of all subtasks.

View File

@ -151,8 +151,8 @@ class SubtaskTimeTrackingTest extends Base
$time = $st->calculateSubtaskTime(1);
$this->assertNotempty($time);
$this->assertCount(2, $time);
$this->assertEquals(3.3, $time['total_spent'], 'Total spent', 0.01);
$this->assertEquals(7.7, $time['total_estimated'], 'Total estimated', 0.01);
$this->assertEquals(3.3, $time['time_spent'], 'Total spent', 0.01);
$this->assertEquals(7.7, $time['time_estimated'], 'Total estimated', 0.01);
}
public function testUpdateSubtaskTimeSpent()
@ -184,13 +184,13 @@ class SubtaskTimeTrackingTest extends Base
$time = $st->calculateSubtaskTime(1);
$this->assertNotempty($time);
$this->assertEquals(4.2, $time['total_spent'], 'Total spent', 0.01);
$this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01);
$this->assertEquals(4.2, $time['time_spent'], 'Total spent', 0.01);
$this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
$time = $st->calculateSubtaskTime(2);
$this->assertNotempty($time);
$this->assertEquals(0, $time['total_spent'], 'Total spent', 0.01);
$this->assertEquals(0, $time['total_estimated'], 'Total estimated', 0.01);
$this->assertEquals(0, $time['time_spent'], 'Total spent', 0.01);
$this->assertEquals(0, $time['time_estimated'], 'Total estimated', 0.01);
}
public function testUpdateTaskTimeTracking()
@ -205,7 +205,7 @@ class SubtaskTimeTrackingTest extends Base
$this->assertEquals(1, $tc->create(array('title' => 'test 1', 'project_id' => 1)));
$this->assertEquals(2, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 1.5, 'time_spent' => 0.5)));
$this->assertEquals(3, $tc->create(array('title' => 'test 2', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2)));
$this->assertEquals(3, $tc->create(array('title' => 'test 3', 'project_id' => 1, 'time_estimated' => 4, 'time_spent' => 2)));
$this->assertEquals(1, $s->create(array('title' => 'subtask #1', 'task_id' => 1, 'time_spent' => 2.2)));
$this->assertEquals(2, $s->create(array('title' => 'subtask #2', 'task_id' => 1, 'time_estimated' => 1)));
@ -231,8 +231,18 @@ class SubtaskTimeTrackingTest extends Base
$task = $tf->getById(3);
$this->assertNotEmpty($task);
$this->assertEquals(4, $task['time_estimated']);
$this->assertEquals(0, $task['time_estimated']);
$this->assertEquals(8, $task['time_spent']);
$this->assertTrue($s->remove(3));
$this->assertTrue($s->remove(4));
$st->updateTaskTimeTracking(2);
$task = $tf->getById(2);
$this->assertNotEmpty($task);
$this->assertEquals(0, $task['time_estimated']);
$this->assertEquals(0, $task['time_spent']);
}
public function testGetCalendarEvents()