[#4183] Implemented Contract#total_spent
This commit is contained in:
@@ -38,7 +38,7 @@ class Contract < ActiveRecord::Base
|
|||||||
define_method(mthd) { "TODO in later release" }
|
define_method(mthd) { "TODO in later release" }
|
||||||
end
|
end
|
||||||
|
|
||||||
[:total_spent,
|
[
|
||||||
:profit_spent
|
:profit_spent
|
||||||
].each do |mthd|
|
].each do |mthd|
|
||||||
define_method(mthd) { "TODO" }
|
define_method(mthd) { "TODO" }
|
||||||
@@ -81,6 +81,11 @@ class Contract < ActiveRecord::Base
|
|||||||
deliverables.inject(0) {|total, deliverable| total += deliverable.total }
|
deliverables.inject(0) {|total, deliverable| total += deliverable.total }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# OPTIMIZE: N+1
|
||||||
|
def total_spent
|
||||||
|
deliverables.inject(0) {|total, deliverable| total += deliverable.total_spent }
|
||||||
|
end
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def profit_budget
|
def profit_budget
|
||||||
deliverables.inject(0) {|total, deliverable| total += deliverable.profit_budget }
|
deliverables.inject(0) {|total, deliverable| total += deliverable.profit_budget }
|
||||||
|
|||||||
@@ -185,4 +185,28 @@ class ContractTest < ActiveSupport::TestCase
|
|||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#total_spent" do
|
||||||
|
should "sum all of the total spents on the Deliverables" do
|
||||||
|
configure_overhead_plugin
|
||||||
|
|
||||||
|
contract = Contract.generate!(:billable_rate => 150.0)
|
||||||
|
|
||||||
|
@project = Project.generate!
|
||||||
|
@developer = User.generate!
|
||||||
|
@role = Role.generate!
|
||||||
|
User.add_to_project(@developer, @project, @role)
|
||||||
|
|
||||||
|
contract.deliverables << @deliverable_1 = FixedDeliverable.generate!(:total => 10_000)
|
||||||
|
contract.deliverables << @deliverable_2 = HourlyDeliverable.generate!(:contract => contract)
|
||||||
|
@deliverable_2.issues << @issue1 = Issue.generate_for_project!(@project)
|
||||||
|
TimeEntry.generate!(:hours => 15, :issue => @issue1, :project => @project,
|
||||||
|
:activity => @billable_activity,
|
||||||
|
:user => @developer)
|
||||||
|
|
||||||
|
assert_equal 10_000, @deliverable_1.total_spent
|
||||||
|
assert_equal 2250, @deliverable_2.total_spent
|
||||||
|
assert_equal 12_250, contract.total_spent
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user