spike008t / redmine_advanced_issues

Advanced issues for redmine
http://blog.spikie.info
7 stars 10 forks source link

Wrong remaining time/hours task/subtask calculation #6

Closed didlich closed 12 years ago

didlich commented 12 years ago

After the installation under redmine-1.3.2 I see in the Issues view that the remaining time calculation of ancestor task is wrong. Before the plugin installation the calculation was correct.

e.g.: two stories (Tasks) with each two tasks (Subtasks) after creation, without time logging

            Name    | Estimated time | Remaining (hours) | Remaining time
            Story 1  |        8        |    16    |         16
            - Task 1|        4        |     4      |         4 
            - Task 2|        4        |     4      |         4
            Story 2  |       20      |     40    |         40
            - Task 3|       10      |     10    |         10
            - Task 4|       10      |     10    |         10

in the issue_patch.rb

the part

      def remaining_hours
        return self_and_descendants.sum("estimated_hours - (estimated_hours * done_ratio / 100)").to_f || 0.0         
      end #remaining_hours

       def remaining_time
        time = RedmineAdvancedIssues::TimeManagement.calculate remaining_hours, Setting.plugin_redmine_advanced_issues['default_unit']
        return nil if time.nil?
        return time.to_f
        #return sprintf "%.2f %c", time.to_f, default_unit_time
      end #remaining_time

seems to be the problem

does sombody know how to fix this?

didlich commented 12 years ago

OK, now I have a patch which solve the problem

   def remaining_hours
                    #print "Leaves-count:", self.leaves.count, "\n"
                    if self.leaves.count > 0
                      rHours=self.leaves.sum(:"estimated_hours - (estimated_hours * done_ratio / 100)").to_f || 0.0
                    else
                      rHours = self_and_descendants.sum("estimated_hours - (estimated_hours * done_ratio / 100)").to_f || 0.0
                    end
                    return rHours
     end #remaining_hours

I dont't know ruby well and also the redmine framwork, maybe there is a better solution for this.