From c9861835e7eea03a62b117baf46e496a076eace7 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Wed, 22 Sep 2010 12:45:04 -0700 Subject: [PATCH] [#4551] Change the Budget conversion to create new FixedBudget items for old FixedDeliverables --- .../budget_plugin_migration.rb | 22 +++++++++++++++++++ .../budget_plugin_migration_test.rb | 14 ++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lib/redmine_contracts/budget_plugin_migration.rb b/lib/redmine_contracts/budget_plugin_migration.rb index b9c22d0..d27b325 100644 --- a/lib/redmine_contracts/budget_plugin_migration.rb +++ b/lib/redmine_contracts/budget_plugin_migration.rb @@ -58,6 +58,8 @@ module RedmineContracts case old_deliverable['type'] when 'FixedDeliverable' @total_cost = old_deliverable['fixed_cost'] + convert_old_fixed_deliverable_to_fixed_budgets(deliverable, old_deliverable) + when 'HourlyDeliverable' @total_cost = old_deliverable['total_hours'].to_f * old_deliverable['cost_per_hour'].to_f @@ -153,6 +155,26 @@ module RedmineContracts end end + def self.convert_old_fixed_deliverable_to_fixed_budgets(deliverable, old_deliverable) + if old_deliverable['fixed_cost'].present? + budget = old_deliverable['fixed_cost'] + else + budget = 0 + end + + if old_deliverable['profit'].present? + markup = old_deliverable['profit'] + elsif old_deliverable['profit_percent'].present? + markup = old_deliverable['profit_percent'].to_s + "%" + else + markup = '0' + end + + deliverable.fixed_budgets << FixedBudget.new(:deliverable => deliverable, + :budget => budget, + :markup => markup) + end + def self.append_old_deliverable_to_notes(old_deliverable, new_deliverable) new_deliverable.notes += "Converted data:\n
" + old_deliverable.pretty_inspect + "
" end diff --git a/test/integration/budget_plugin_migration_test.rb b/test/integration/budget_plugin_migration_test.rb index 22d93ca..69bad59 100644 --- a/test/integration/budget_plugin_migration_test.rb +++ b/test/integration/budget_plugin_migration_test.rb @@ -115,7 +115,7 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest end should "create a new Fixed Budget record for any materials" do - assert_difference("FixedBudget.count", 2) do + assert_difference("FixedBudget.count", 3) do RedmineContracts::BudgetPluginMigration.migrate(@data) end @@ -125,7 +125,7 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest end should "create a new Fixed Budget record for any materials percent" do - assert_difference("FixedBudget.count", 2) do + assert_difference("FixedBudget.count", 3) do RedmineContracts::BudgetPluginMigration.migrate(@data) end @@ -153,6 +153,16 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest d = FixedDeliverable.find_by_title("Version 1.0") assert_equal 93_000, d.total end + + should "add a FixedBudget item for the total deliverable" do + RedmineContracts::BudgetPluginMigration.migrate(@data) + d = FixedDeliverable.find_by_title("Version 1.0") + + assert_equal 1, d.fixed_budgets.count + fixed_budget_item = d.fixed_budgets.first + assert_equal 30_000, fixed_budget_item.budget + assert_equal "150%", fixed_budget_item.markup + end end context "converting Hourly Deliverables" do