Skip to content

Instantly share code, notes, and snippets.

@lucasmartins
Created February 28, 2013 13:47
Show Gist options
  • Save lucasmartins/5056829 to your computer and use it in GitHub Desktop.
Save lucasmartins/5056829 to your computer and use it in GitHub Desktop.
Rake Task para Relatório de Tempo Restante do Redmine
#@author: Lucas Martins
namespace :report do
desc 'Reports remaining time of tasks under work'
task :remaining => :environment do
data = []
Issue.find(:all, :conditions => ['status_id in (?)', [2,4] ],:order=>'id').each do |issue|
remaining = issue.estimated_hours-issue.spent_hours
puts "##{issue.id} '#{issue.subject}' => remaining: #{remaining}, spent: #{issue.spent_hours}, estimated: #{issue.estimated_hours}"
subtasks = []
issue.descendants.each do |subtask|
st_remaining = subtask.estimated_hours-subtask.spent_hours
subtasks.push({:id=>subtask.id, :subject=>subtask.subject, :estimated=>subtask.estimated_hours, :spent=>subtask.spent_hours, :remaining=>st_remaining})
puts " - ##{subtask.id} '#{subtask.subject}' => remaining: #{st_remaining}, spent: #{subtask.spent_hours}, estimated: #{subtask.estimated_hours}"
end
data.push({:id=>issue.id, :subject=>issue.subject, :estimated=>issue.estimated_hours, :spent=>issue.spent_hours, :remaining=>remaining, :subtasks=>[subtasks]})
end
path = "/home/innovit/redmine_report_remaining-#{Date.today.to_s}.json"
file = File.open(path,'w')
file.write data.to_json
file.close
puts "\nUm relatório foi gravado em: #{path}\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment