[#2847] Added Deliverable#overhead_spent to calculate the overhead cost so far.
This commit is contained in:
1 parent
79847e36c0
commit
cd826e7cd6
3 files changed
+70
No files matched your search
@@ -2,10 +2,12 @@ require 'redmine'
|
|||||||
|
|
||||||
# Patches to the Redmine core.
|
# Patches to the Redmine core.
|
||||||
require 'dispatcher'
|
require 'dispatcher'
|
||||||
|
require 'overhead_deliverable_patch'
|
||||||
require 'overhead_issue_patch'
|
require 'overhead_issue_patch'
|
||||||
require 'overhead_time_entry_patch'
|
require 'overhead_time_entry_patch'
|
||||||
require 'overhead_time_entry_activity_patch'
|
require 'overhead_time_entry_activity_patch'
|
||||||
Dispatcher.to_prepare do
|
Dispatcher.to_prepare do
|
||||||
|
Deliverable.send(:include, OverheadDeliverablePatch)
|
||||||
Issue.send(:include, OverheadIssuePatch)
|
Issue.send(:include, OverheadIssuePatch)
|
||||||
TimeEntry.send(:include, OverheadTimeEntryPatch)
|
TimeEntry.send(:include, OverheadTimeEntryPatch)
|
||||||
TimeEntryActivity.send(:include, OverheadTimeEntryActivityPatch)
|
TimeEntryActivity.send(:include, OverheadTimeEntryActivityPatch)
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
require_dependency 'deliverable'
|
||||||
|
|
||||||
|
module OverheadDeliverablePatch
|
||||||
|
def self.included(base)
|
||||||
|
base.send(:include, InstanceMethods)
|
||||||
|
|
||||||
|
base.class_eval do
|
||||||
|
unloadable
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
module InstanceMethods
|
||||||
|
# Cost of time logged to overhead activities
|
||||||
|
def overhead_spent
|
||||||
|
time_logs = issues.collect(&:time_entries).flatten
|
||||||
|
|
||||||
|
return time_logs.collect {|time_entry|
|
||||||
|
if time_entry.billable?
|
||||||
|
0
|
||||||
|
else
|
||||||
|
time_entry.cost
|
||||||
|
end
|
||||||
|
}.sum
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
require File.dirname(__FILE__) + '/../spec_helper'
|
||||||
|
|
||||||
|
describe Deliverable, '#overhead_spent' do
|
||||||
|
before(:each) do
|
||||||
|
@deliverable = Deliverable.new
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should equal the product of overhead timelogs by their cost' do
|
||||||
|
issue1 = mock_model(Issue)
|
||||||
|
issue1.stub!(:time_entries).and_return do
|
||||||
|
[
|
||||||
|
mock_model(TimeEntry, :cost => 100.0, :billable? => true),
|
||||||
|
mock_model(TimeEntry, :cost => 200.0, :billable? => false)
|
||||||
|
]
|
||||||
|
end
|
||||||
|
issue2 = mock_model(Issue)
|
||||||
|
issue2.stub!(:time_entries).and_return do
|
||||||
|
[
|
||||||
|
mock_model(TimeEntry, :cost => 10.0, :billable? => false),
|
||||||
|
mock_model(TimeEntry, :cost => 40.0, :billable? => false)
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
issues = [issue1, issue2]
|
||||||
|
|
||||||
|
@deliverable.stub!(:issues).and_return(issues)
|
||||||
|
@deliverable.overhead_spent.should eql(250.0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be 0.0 if there are no issues assigned' do
|
||||||
|
@deliverable.stub!(:issues).and_return([])
|
||||||
|
@deliverable.overhead_spent.should eql(0)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should be 0.0 if there are no time entries' do
|
||||||
|
issue1 = mock_model(Issue, :time_entries => [])
|
||||||
|
issue2 = mock_model(Issue, :time_entries => [])
|
||||||
|
|
||||||
|
@deliverable.stub!(:issues).and_return([issue1, issue2])
|
||||||
|
@deliverable.overhead_spent.should eql(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in new issue
Block a user