[#4183] Updated HourlyDeliverable#total to calculate the estimated total

This commit is contained in:
Eric Davis
2010-07-07 16:00:40 -07:00
parent 26aac777e4
commit 91b16a2310
4 changed files with 42 additions and 5 deletions
+4
View File
@@ -11,6 +11,10 @@ class FixedDeliverable < Deliverable
'F'
end
def total
read_attribute(:total) || 0.0
end
# Hardcoded value used as a wrapper for the old Budget plugin API.
#
# The Overhead plugin uses this in it's calcuations.
+7 -2
View File
@@ -14,11 +14,16 @@ class HourlyDeliverable < Deliverable
'H'
end
# Block getting and setting the total on HourlyDeliverables
def total
nil
return 0 if contract.nil?
return 0 if contract.billable_rate.blank?
return 0 if labor_budgets.count == 0 && overhead_budgets.count == 0
hours = labor_budgets.sum(:hours) + overhead_budgets.sum(:hours)
return contract.billable_rate * hours
end
# Block setting the total on HourlyDeliverables
def total=(v)
nil
end
@@ -108,7 +108,6 @@ class DeliverablesNewTest < ActionController::IntegrationTest
assert_equal '2010-01-01', @deliverable.start_date.to_s
assert_equal '2010-12-31', @deliverable.end_date.to_s
assert_equal @manager, @deliverable.manager
assert_equal nil, @deliverable.total
end
+31 -2
View File
@@ -1,12 +1,41 @@
require File.dirname(__FILE__) + '/../test_helper'
class HourlyDeliverableTest < ActiveSupport::TestCase
context "#total" do
should "be 0 when not assigned to a contract" do
assert_equal 0, HourlyDeliverable.new.total
end
should "be 0 with no billable rate set on the Contract" do
contract = Contract.generate!(:billable_rate => nil)
d = HourlyDeliverable.generate!(:contract => contract)
assert_equal 0, d.total
end
should "be 0 with no budgets" do
contract = Contract.generate!(:billable_rate => 100.0)
d = HourlyDeliverable.generate!(:contract => contract)
assert_equal 0, d.total
end
should "multiply the total number of budgeted hours by the contract billable rate" do
contract = Contract.generate!(:billable_rate => 100.0)
d = HourlyDeliverable.generate!(:contract => contract)
d.labor_budgets << LaborBudget.generate!(:hours => 10)
d.overhead_budgets << OverheadBudget.generate!(:hours => 20)
assert_equal 100.0 * 30, d.total
end
end
context "#total=" do
should "not write any attributes" do
d = HourlyDeliverable.new
d.total = '$100.00'
assert_equal nil, d.total
assert_equal nil, d.read_attribute(:total)
end
end
@@ -16,7 +45,7 @@ class HourlyDeliverableTest < ActiveSupport::TestCase
d.write_attribute(:total, 100.00)
d.clear_total
assert_equal nil, d.total
assert_equal nil, d.read_attribute(:total)
end
end