[#4674] Add an option for an overhead rate which computes overhead hours

This commit is contained in:
Eric Davis
2010-10-21 10:30:28 -07:00
parent a302c17b04
commit 2957d8e2cc
3 changed files with 61 additions and 23 deletions

View File

@@ -41,6 +41,8 @@ module RedmineContracts
# @option options [boolean] :append_object_notes show the old Budget data be
# added to the Deliverable notes (for debugging)
# Defaults to true (will append)
# @option options [float] :overhead_rate the overhead rate to use when calculating hours.
# Defaults to 0
def self.migrate(old_data, options={})
@contract_rate = options[:contract_rate] ? options[:contract_rate].to_f : 150.0
@account_executive = if options[:account_executive].present?
@@ -53,6 +55,7 @@ module RedmineContracts
end
@append_object_notes = options[:append_object_notes].nil? ? true : options[:append_object_notes]
@overhead_rate = options[:overhead_rate].nil? ? 0 : options[:overhead_rate].to_f
@@data = YAML.load(old_data)
@@ -148,14 +151,26 @@ module RedmineContracts
total ||= 0
if old_deliverable['overhead'].present?
if @overhead_rate != 0
hours = old_deliverable['overhead'] / @overhead_rate
else
hours = 0
end
deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable,
:budget => old_deliverable['overhead'],
:hours => 0)
:hours => hours)
elsif old_deliverable['overhead_percent'].present?
overhead = total * (old_deliverable['overhead_percent'].to_f / 100)
if @overhead_rate != 0
hours = overhead / @overhead_rate
else
hours = 0
end
deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable,
:budget => overhead,
:hours => 0)
:hours => hours)
end
end

View File

@@ -6,6 +6,7 @@ namespace :redmine_contracts do
options[:account_executive] = ENV['account_executive']
options[:deliverable_manager] = ENV['deliverable_manager']
options[:append_object_notes] = ENV['append_object_notes']
options[:overhead_rate] = ENV['overhead_rate']
RedmineContracts::BudgetPluginMigration.check_for_installed_budget_plugin
data = RedmineContracts::BudgetPluginMigration.export_data

View File

@@ -120,36 +120,58 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest
assert_equal [@other_user, @other_user, @other_user], Deliverable.all.collect(&:manager)
end
should "create a new Overhead Budget record for any overhead" do
assert_difference("OverheadBudget.count", 3) do
RedmineContracts::BudgetPluginMigration.migrate(@data)
context "Overhead Budgets" do
should "create a new Overhead Budget record for any overhead" do
assert_difference("OverheadBudget.count", 3) do
RedmineContracts::BudgetPluginMigration.migrate(@data)
end
d = Deliverable.find_by_title("Deliverable One")
assert_equal 1, d.overhead_budgets.count
assert_equal 200, d.overhead_budget_total
overhead = d.overhead_budgets.first
assert overhead
assert_equal 200, overhead.budget
assert_equal 0, overhead.hours
end
d = Deliverable.find_by_title("Deliverable One")
assert_equal 1, d.overhead_budgets.count
assert_equal 200, d.overhead_budget_total
should "create a new Overhead Budget record for any overhead percent" do
assert_difference("OverheadBudget.count", 3) do
RedmineContracts::BudgetPluginMigration.migrate(@data)
end
overhead = d.overhead_budgets.first
assert overhead
assert_equal 200, overhead.budget
assert_equal 0, overhead.hours
end
d = Deliverable.find_by_title("Deliverable 2")
assert_equal 1, d.overhead_budgets.count
overhead = d.overhead_budgets.first
assert overhead
assert_equal 12 * 25 * 1.5, overhead.budget
assert_equal 0, overhead.hours
should "create a new Overhead Budget record for any overhead percent" do
assert_difference("OverheadBudget.count", 3) do
RedmineContracts::BudgetPluginMigration.migrate(@data)
end
d = Deliverable.find_by_title("Deliverable 2")
assert_equal 1, d.overhead_budgets.count
should "allow setting an overhead rate to compute the overhead hours" do
RedmineContracts::BudgetPluginMigration.migrate(@data, :overhead_rate => 100.0)
overhead = d.overhead_budgets.first
assert overhead
assert_equal 12 * 25 * 1.5, overhead.budget
assert_equal 0, overhead.hours
d1 = Deliverable.find_by_title("Deliverable One")
assert_equal 1, d1.overhead_budgets.count
assert_equal 200, d1.overhead_budget_total
overhead = d1.overhead_budgets.first
assert overhead
assert_equal 2, overhead.hours
d2 = Deliverable.find_by_title("Deliverable 2")
assert_equal 1, d2.overhead_budgets.count
overhead = d2.overhead_budgets.first
assert overhead
assert_equal 4.5, overhead.hours
end
end
should "create a new Fixed Budget record for any materials" do
assert_difference("FixedBudget.count", 3) do
RedmineContracts::BudgetPluginMigration.migrate(@data)