[#4183] Implemented Contract#labor_spent.
This commit is contained in:
@@ -38,8 +38,7 @@ class Contract < ActiveRecord::Base
|
|||||||
define_method(mthd) { "TODO in later release" }
|
define_method(mthd) { "TODO in later release" }
|
||||||
end
|
end
|
||||||
|
|
||||||
[:labor_spent,
|
[:total_spent,
|
||||||
:total_spent,
|
|
||||||
:profit_spent
|
:profit_spent
|
||||||
].each do |mthd|
|
].each do |mthd|
|
||||||
define_method(mthd) { "TODO" }
|
define_method(mthd) { "TODO" }
|
||||||
@@ -50,6 +49,12 @@ class Contract < ActiveRecord::Base
|
|||||||
deliverables.inject(0) {|total, deliverable| total += deliverable.labor_budget_total }
|
deliverables.inject(0) {|total, deliverable| total += deliverable.labor_budget_total }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# OPTIMIZE: N+1
|
||||||
|
# OPTIMIZE: also hits redmine_overhead which is known to be slow
|
||||||
|
def labor_spent
|
||||||
|
deliverables.inject(0) {|total, deliverable| total += deliverable.labor_budget_spent }
|
||||||
|
end
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def overhead_budget
|
def overhead_budget
|
||||||
deliverables.inject(0) {|total, deliverable| total += deliverable.overhead_budget_total }
|
deliverables.inject(0) {|total, deliverable| total += deliverable.overhead_budget_total }
|
||||||
|
|||||||
@@ -45,6 +45,39 @@ class ContractTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#labor_spent" do
|
||||||
|
setup do
|
||||||
|
configure_overhead_plugin
|
||||||
|
end
|
||||||
|
|
||||||
|
should "sum all of the labor spent on the Deliverables" do
|
||||||
|
@project = Project.generate!
|
||||||
|
@manager = User.generate!
|
||||||
|
@role = Role.generate!
|
||||||
|
User.add_to_project(@manager, @project, @role)
|
||||||
|
@rate = Rate.generate!(:project => @project,
|
||||||
|
:user => @manager,
|
||||||
|
:date_in_effect => Date.yesterday,
|
||||||
|
:amount => 100)
|
||||||
|
|
||||||
|
contract = Contract.generate!
|
||||||
|
contract.deliverables << @deliverable_1 = FixedDeliverable.generate!
|
||||||
|
@deliverable_1.issues << @issue1 = Issue.generate_for_project!(@project)
|
||||||
|
TimeEntry.generate!(:hours => 5, :issue => @issue1, :project => @project,
|
||||||
|
:activity => @billable_activity,
|
||||||
|
:user => @manager)
|
||||||
|
|
||||||
|
contract.deliverables << @deliverable_2 = HourlyDeliverable.generate!
|
||||||
|
@deliverable_2.issues << @issue2 = Issue.generate_for_project!(@project)
|
||||||
|
TimeEntry.generate!(:hours => 20, :issue => @issue2, :project => @project,
|
||||||
|
:activity => @billable_activity,
|
||||||
|
:user => @manager)
|
||||||
|
|
||||||
|
assert_equal 2500, contract.labor_spent
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "#overhead_budget" do
|
context "#overhead_budget" do
|
||||||
should "sum all of the overhead budgets of the Deliverables" do
|
should "sum all of the overhead budgets of the Deliverables" do
|
||||||
contract = Contract.generate!
|
contract = Contract.generate!
|
||||||
|
|||||||
Reference in New Issue
Block a user