Project

General

Profile

How to show the sum of estimated hours in the specified query?

Added by clawfrown clawfrown over 16 years ago

This is duplicate to #1374

How can I show the sum of all estimated hours right on the top of the custom query list.
The same as we can see in Roadmap/Version > Time Tracking field - but recalculated for every query I make..

Can somebody say how to code that?
For example in version/time tracking it's made like this:
<%= html_hours(lwr(:label_f_hour, @version.estimated_hours)) %>

I'd like something like this (like an example):
<%= html_hours(lwr(:label_f_hour, @query.estimated_hours)) %>

I suppose there must be something written in query_controllers.rb or so..
Unfortunately, my Ruby and general programming knowledge doesn't allow to cope with that myself..
Please help! :-)


Replies (4)

RE: How to show the sum of estimated hours in the specified query? - Added by clawfrown clawfrown over 16 years ago

For example in version/time tracking it's made like this:

<%= html_hours(lwr(:label_f_hour, @version.estimated_hours)) %>

I'd like something like this (like an example):

<%= html_hours(lwr(:label_f_hour, @query.estimated_hours)) %>

RE: How to show the sum of estimated hours in the specified query? - Added by clawfrown clawfrown over 16 years ago

Or rather how can I sum estimated_hours variable in all issues in the query? How it shall be written?

RE: How to show the sum of estimated hours in the specified query? - Added by Eric Davis over 16 years ago

You will need to use a set of Issues for that, Query is used to build the set of issues.

# See issues_controller.rb#index for the actual query filter
@issue_list = Issue.find :all, :conditions => @query.statement

# Take only the estimated_hours column, remove hours that are blank, and sum the amounts
estimated_hours = @issue_list.collect(&:estimated_hours).reject {|issue| issue.blank? }.sum

Eric

RE: How to show the sum of estimated hours in the specified query? - Added by clawfrown clawfrown over 16 years ago

Thank you so much Eric!!! You saved me hours of brainstorming!!! :-)

Btw. If to do this right in the issues section, it's possible to limit this task into one line:

 <%= estimated_hours = @issues.collect(&:estimated_hours).reject {|issue| issue.blank? }.sum %> 

Well.. at least it worked for me on 0.7_rc1 version.

Once again, thank you very much indeed, Eric.

    (1-4/4)