Patch #4776

Totals for Estimated Time

Added by Ewan Makepeace over 7 years ago. Updated almost 2 years ago.

Status:ClosedStart date:2010-02-09
Priority:NormalDue date:
Assignee:-% Done:

50%

Category:Issues
Target version:-

Description

We use the estimated time field extensively to both manage our work and reward our developers. We have developed two patches for Redmine that I find indispensible. One was previously posted and I thought had been accepted into the trunk, but does not seem to be there in 0.9. The other we have created to improve the (fantastic) new 'Group By' functionality.

The older patch gives Total Estimated Time for all issues on the page, and all issues across all pages, at the bottom of all issue lists:

The second provides a total of the estimated times of issues in a sub group:

We are not a Ruby shop - the code can probably be improved. If so please post back here!

PS: I tried to post a patch here once before and it was an embarrassing failure. Apologies in advance if this does not work out again!

total.jpg (23.4 KB) Ewan Makepeace, 2010-02-09 08:25

grouptotal.jpg (26.9 KB) Ewan Makepeace, 2010-02-09 08:25

TotalEstimatedTime.patch Magnifier (7.33 KB) Ewan Makepeace, 2010-02-09 08:25

sumEstimatedTimeByGroup.patch Magnifier (2.8 KB) Ewan Makepeace, 2010-02-09 08:25

subtotal-decimal.png - subtotal rounding bug (684 Bytes) Victor Sergienko, 2010-11-22 15:24

sumEstimatedTimeByGroup.patch Magnifier (2.79 KB) Ewan Makepeace, 2010-11-23 05:08

totalTime.patch Magnifier (1.01 KB) Ewan Makepeace, 2010-11-23 05:08

estimated_hour_exclude_parent.diff Magnifier (3.37 KB) RedminePro Yang, 2011-04-19 14:40

estimatedTime.diff Magnifier - Diff file for Redmine 2.3.3 (3.41 KB) Olivier Houdas, 2013-10-17 13:20

estimatedTime-v2.dif (3.54 KB) Olivier Houdas, 2014-01-16 09:42

Redmine.org-4776-Estimated time patch for RM 3.0.3.patch Magnifier (8.78 KB) Olivier Houdas, 2015-06-24 19:33

RM3.0.3-Estimated-and-spent-times.png (57.5 KB) Olivier Houdas, 2015-06-25 11:19

Redmine.org-4776-Estimated-time-patch_v1.1-for-RM-3.1.0.patch Magnifier (9.71 KB) Olivier Houdas, 2015-08-14 16:14


Related issues

Related to Redmine - Feature #1561: Totals for estimated/spent time and numeric custom fields... Closed 2008-07-02
Related to Redmine - Feature #6571: Totalise numeric columns Closed 2010-10-05
Related to Redmine - Feature #8559: Sum columns in reports Closed 2011-06-07
Follows Redmine - Patch #2268: Patch to show Total Estimated Time at the bottom of each ... Closed 2008-12-03

History

#1 Updated by Victor Sergienko almost 7 years ago

Thank you a lot!

What version is the for? TotalEstimatedTime.patch didn't apply to my 1.0.3 (2010-10-31), though sumEstimatedTimeByGroup.patch did.

I also got a rounding bug from somewhere, see subtotal-decimal.png attachment. I don't have such a fractional estimations :)

#2 Updated by Ewan Makepeace almost 7 years ago

I believe this is our latest version, running on 1.0.2.
Let me know if it still gives errors.

#3 Updated by Victor Sergienko over 6 years ago

May I ask you one more thing? On Redmine 1.1, with subtasks, it counts subtasks' hours alongside with parent's, so a subtask gets counted twice.
Can you please exclude issues with nonempty children?
Thanks.

#4 Updated by Ewan Makepeace over 6 years ago

I know - it is a real pain. We are looking to update as you suggest. Will advise here.

#5 Updated by RedminePro Yang over 6 years ago

With the attached patch, the parent task is excluded when sum the estimated hours for both current page and all pages.

#6 Updated by Ewan Makepeace over 6 years ago

+1

We are using this to exclude parents from totals on current page, all pages and group totals. Note however that it does not (I think) exclude parents from CSV listings ect.

#7 Updated by David Marín Carreño over 6 years ago

+1
Please, get this functionality into the main trunk.

#8 Updated by Terence Mill over 6 years ago

+1 FOR..

Calculated fields can be optionally switched on per poeject and tracker and field.

...calculation can be

  • sum
  • average
  • max
  • min

...Calculcated values can be shown for

  • a task (included subtash ) in issue form, e.g at the bottom
  • issue list as summary for filtered issues (mean same values on every page if search result is splitted on several result pages)
  • on issue list group level a total for every group

We would need that for estimation and spent time and total numer of issues for a group

#10 Updated by Terence Mill about 6 years ago

+1

Please include this!

Totals for all number type fields on group header/footer is fundamental requirement here.

#11 Updated by Jérôme BATAILLE about 6 years ago

+1

#12 Updated by Mischa The Evil almost 6 years ago

As mentioned the first time by Tony Marschall in #8559 note-4, there exists a plugin which provides (parts of) this feature (along with some others): Redmine spent time column. It's written by Jan Schulz-Hofen of plan.io.

I've started working on some improvements to make it better suitable for this issue in my fork of it:
https://github.com/MischaTheEvil/redmine_spent_time_column

#13 Updated by Matej Kenda almost 6 years ago

I vote for inclusion of this patch into the release 1.2.2.

#14 Updated by Giovani Spagnolo almost 6 years ago

+1

#15 Updated by Terence Mill almost 6 years ago

+1

#16 Updated by Matej Kenda almost 6 years ago

Matej Kenda wrote:

I vote for inclusion of this patch into the release 1.2.2.

Or 1.2.3 since 1.2.2 was just released.

#17 Updated by Nicolas Ottavi over 5 years ago

Hi,

My two cents, I am not a redmine export nor a ruby developer at all, but I was wondering if adding function which return the total estimation time in the project Model would not be a good solution. This way we could use this value anywhere in redmine where projects are listed ?

def estimated_duration
      issues.sum(:estimated_hours, :include => [:status,:project], :conditions => Issue.merge_conditions(nil, "#{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1"))
rescue ::ActiveRecord::StatementInvalid => e
      raise StatementInvalid.new(e.message)
end

#18 Updated by strexy strexy about 5 years ago

Hello everybody,
is this useful patch compatible with Redmine 0.9.3 stable ?

Thanks in advance.

#19 Updated by Ewan Makepeace about 5 years ago

We are currently running 1.3 and I could not use redmine without these group and running totals. However the first attached version of the patch was written for 0.9 so I think there is a good chance it would run with 0.9.3

#20 Updated by strexy strexy about 5 years ago

Hi all,
on my 0.9.3 I've successfully installed the TotalEstimatedTime.patch but the very useful sumEstimatedTimeByGroup.patch generates an error as I try to group a tasks list.

It seems that this
<%= @issue_sum_by_group[group] %> (line 22 of views/issues/_list.rhtml)
is not compatible for whatever reason.

It's declared in models/query.rb

#Returns sum of the issue's estimated_hours by group or nil if query is not grouped
def issue_sum_by_group
r = nil
if grouped?
begin
r = Issue.sum(:estimated_hours, :group => group_by_statement, :include => [:status, :project], :conditions => statement)
rescue ActiveRecord::RecordNotFound
r= {r => issue_sum}
end

c = group_by_column
if c.is_a?(QueryCustomFieldColumn)
r = r.keys.inject({}) {|h, k| h[c.custom_field.cast_value(k)] = r[k]; h}
end
end
r
rescue ::ActiveRecord::StatementInvalid => e
raise StatementInvalid.new(e.message)
end

Maybe someone have already solved this issue.
I'm not a coder at all.
Thanks in advance.

#21 Updated by Bill Wang about 5 years ago

the error msg?

#22 Updated by strexy strexy about 5 years ago

ActionView::TemplateError (undefined method `[]' for nil:NilClass) on line #22 of app/views/issues/_list.rhtml:

19: <tr class="group open">
20: <td colspan="<%= query.columns.size + 2 >">
21: <span class="expander" onclick="toggleRowGroup(this); return false;"> </span>
22: <
= group.blank? ? 'None' : column_content(@query.group_by_column, issue) > <span class="count">(<= @issue_sum_by_group[group] >)</span>
23: </td>
24: </tr>
25: <
previous_group = group %>

#23 Updated by Bill Wang about 5 years ago

hi strexy, it means @issue_sum_by_group is nil.

so, maybe:
1. check whether you missed something.

--- app/controllers/issues_controller.rb    (revision 4884)
+++ app/controllers/issues_controller.rb    (working copy)
@@ -85,7 +85,8 @@
                               :order => sort_clause, 
                               :offset => @offset, 
                               :limit => @limit)
-      @issue_count_by_group = @query.issue_count_by_group
+      @issue_count_by_group = @query.issue_count_by_group                        
+      @issue_sum_by_group = @query.issue_sum_by_group

2.
+   # Returns  sum of the issue's estimated_hours by group or nil if query is not grouped
+  def issue_sum_by_group
+    r = nil
+    if grouped?
+      begin
+        r = Issue.sum(:estimated_hours, :group => group_by_statement, :include => [:status, :project], 
+        :conditions => Issue.merge_conditions(statement ,  "#{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1"))
+      rescue ActiveRecord::RecordNotFound
+        r= {r => issue_sum}
+      end
+      
+      c = group_by_column
+      if c.is_a?(QueryCustomFieldColumn)
+        r = r.keys.inject({}) {|h, k| h[c.custom_field.cast_value(k)] = r[k]; h}
+      end
+    end
+    r
+  rescue ::ActiveRecord::StatementInvalid => e
+    raise StatementInvalid.new(e.message)
+  end
+  

maybe because of "nil if query is not grouped".
however, accodring to my testing in my redmine, it will not go that line code if not groupd.

<% if @query.grouped? && (group = @query.group_by_column.value(issue)) != previous_group %>      <--it means has_groupd and this_groupd is not equal to previous_group.

so I guess you missed something.

#24 Updated by strexy strexy about 5 years ago

Thanks Bill,
for sure I've missed something.

As you said, it didn't worked only when grouped.

I'll check it after my vacations.
I'll let you know.
Thanks.

#25 Updated by michel p over 4 years ago

Hi,

I try to use the patch... without even know how to code "hello world" with ruby :)

Can someone is able to convert the ":conditions => Issue.merge_conditions(statement..." with scope ?
I use version 2.3.1 and merge_condition seems an deprecated way to do the stuff

thx

#26 Updated by michel p over 4 years ago

UPDATE:

it seems that works with this patch:

-:conditions => Issue.merge_conditions(statement , "#{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1"))
+:conditions => [(statement), ("#{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1")])

there is 2 lines like this in the patch

I'm not sure that this kind of code is correct so if a ruby coder can produce a valid patch for rails 3 it would be better

Hope that can help

#27 Updated by Olivier Houdas about 4 years ago

It almost did it, but actually created an issue for filters which use the Contains operator.
Indeed, that filtering operator results in conditions like "WHERE LOWER LIKE '%test%'", which raised the error : "ActionView::Template::Error (invalid format character - %):" when using the array.
I have changed it to
-:conditions => Issue.merge_conditions(statement , "#{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1"))
+:conditions => statement << "AND #{Issue.table_name}.rgt - #{Issue.table_name}.lft = 1")
which seems to work.

I'm attaching the .diff file for Redmine 2.3.3 to help even more.
Note that in addition to that change, I slightly modified the text displayed in this version, so that it indicates "estimated time : xx hours" instead of just a number.

The patch contains a hardcoded string for the end of page summary ("current page"), I did not change that.

#28 Updated by nicola mondinelli almost 4 years ago

Olivier Houdas wrote:

I'm attaching the .diff file for Redmine 2.3.3 to help even more.
Note that in addition to that change, I slightly modified the text displayed in this version, so that it indicates "estimated time : xx hours" instead of just a number.

The patch contains a hardcoded string for the end of page summary ("current page"), I did not change that.

Oliver, i spotted a issue in the patch: on grouping on custom field i've got a 500 error:

Query::StatementInvalid: Mysql2::Error: Unknown column 'cf_5.value' in 'field list': SELECT SUM(`issues`.`estimated_hours`) AS sum_estimated_hours, COALESCE(cf_5.value, '') AS coalesce_cf_5_value FROM `issues` LEFT OUTER JOIN `issue_statuses` ON `issue_statuses`.`id` = `issues`.`status_id` LEFT OUTER JOIN `projects` ON `projects`.`id` = `issues`.`project_id` WHERE ((issues.status_id IN (SELECT id FROM issue_statuses WHERE is_closed=0)) AND projects.id = 15 AND issues.rgt - issues.lft = 1) GROUP BY COALESCE(cf_5.value, '')

#29 Updated by Olivier Houdas almost 4 years ago

True, Nicola. I fixed it in this patch: estimatedTime-v2.dif

#30 Updated by Jessica Berriman over 3 years ago

I'm trying to install this plugin/patch to our Redmine configuration (4.2 on Windows), but I'm admittedly new to Redmine and am not sure how to get this functionality installed.

Could anyone provide guidance for this?

Much appreciated in advance!

#31 Updated by Jan from Planio www.plan.io over 3 years ago

This tracker is for Redmine bugs/features/patches only. To request guidance, please ask in the forums. Thanks!

#32 Updated by Oscar Corsvall over 3 years ago

Does this patch work with redmine 2.5.0?

#33 Updated by Ewan Makepeace over 3 years ago

We are still on Redmine 2.0.3.devel.10073 - I am surprised we have got so far behind, I need to check what is new in Redmine!

#34 Updated by Olivier Houdas over 3 years ago

I did upgrade sucessfully with this code (estimatedTime-v2.dif ) to 2.4.3. I haven't upgraded to 2.5.1 yet.

#35 Updated by Artem Karamov over 2 years ago

Can anybody confirm if this nice patch work with redmine 3.0.3?

#36 Updated by Olivier Houdas over 2 years ago

It does not: some code was moved to a helper file between 2.6 and 3.0.

You will find attached the patch of our changes on 3.0.3.
It also includes displaying spent time subtotals for grouped queries.
Note that when parents tasks are shown with their children in the same group, the spent time is counted twice. I haven't found out how to fix that issue so far.
I also haven't found how to manage to get spent time when the issues are grouped by project.

I don't guarantee the quality of the code, as I'm pretty new to Ruby... remarks / improvements are welcome!

#37 Updated by Olivier Houdas over 2 years ago

For those interested, here is a screenshot of how we use the patch.
We manage our Agile sprints on Redmine, and this query filters on one sprint, grouping test tasks per product.

We group by tester to ensure the load is evenly spread, and by product to inform product owners about the planned test efforts.

#38 Updated by Ewan Makepeace over 2 years ago

It seems we have a couple of issues covering the same issue. We recently posted our current patch version on this issue #2268 but not here.

No change in functionality - just tracking redmine changes, I am completely unsure how that code and the code describes here differs.

#39 Updated by Artem Karamov over 2 years ago

Thank you very much, Olivier! Installed it on 3.0.3
Very useful patch for planning and review of previous sprints/versions

#40 Updated by Olivier Houdas about 2 years ago

I fixed a case of Error 500 on the previous patch, which happens when sorting on a column selected for grouping.
Attached is the full patch with the fix, produced on Redmine 3.1.0.

#41 Updated by Jonathan Vargas about 2 years ago

This worked fine for us. I just removed the unpaired parentheses at the footer of the query results. Thanks, I'm not Ruby developer, but could this patch be a plugin instead?

#42 Updated by Toshi MARUYAMA almost 2 years ago

  • Status changed from New to Closed

I think this issue is fixed by #1561.
If you have more request, please create new issue.

Also available in: Atom PDF