diff --git a/lib/redmine_contracts/budget_plugin_migration.rb b/lib/redmine_contracts/budget_plugin_migration.rb index 62ff085..4a7c449 100644 --- a/lib/redmine_contracts/budget_plugin_migration.rb +++ b/lib/redmine_contracts/budget_plugin_migration.rb @@ -84,6 +84,18 @@ module RedmineContracts end + if old_deliverable['materials'].present? && old_deliverable['materials'] > 0.0 + deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable, + :budget => old_deliverable['materials'], + :hours => 0) + elsif old_deliverable['materials_percent'].present? && old_deliverable['materials_percent'] > 0.0 + materials = @total * (old_deliverable['materials_percent'].to_f / 100) + deliverable.overhead_budgets << OverheadBudget.new(:deliverable => deliverable, + :budget => materials, + :hours => 0) + + end + deliverable.notes += "Converted data:\n
" + old_deliverable.pretty_inspect + "
" deliverable.save! diff --git a/test/fixtures/budget_plugin_migration/budget.yml b/test/fixtures/budget_plugin_migration/budget.yml index 5bb71a3..52129b3 100644 --- a/test/fixtures/budget_plugin_migration/budget.yml +++ b/test/fixtures/budget_plugin_migration/budget.yml @@ -31,7 +31,7 @@ profit: overhead_percent: 150 description: "" - materials_percent: + materials_percent: 10 due: 2008-06-18 budget: 900.0 client_signoff: false diff --git a/test/integration/budget_plugin_migration_test.rb b/test/integration/budget_plugin_migration_test.rb index 53b153a..ac94c94 100644 --- a/test/integration/budget_plugin_migration_test.rb +++ b/test/integration/budget_plugin_migration_test.rb @@ -60,13 +60,13 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest end should "create a new Overhead Budget record for any overhead" do - assert_difference("OverheadBudget.count", 3) do + assert_difference("OverheadBudget.count", 5) 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 + assert_equal 2, d.overhead_budgets.count + assert_equal 400, d.overhead_budget_total overhead = d.overhead_budgets.first assert overhead @@ -75,7 +75,7 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest end should "create a new Overhead Budget record for any overhead percent" do - assert_difference("OverheadBudget.count", 3) do + assert_difference("OverheadBudget.count", 5) do RedmineContracts::BudgetPluginMigration.migrate(@data) end @@ -90,6 +90,35 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest end + should "create a new Overhead Budget record for any materials" do + assert_difference("OverheadBudget.count", 5) do + RedmineContracts::BudgetPluginMigration.migrate(@data) + end + + d = Deliverable.find_by_title("Deliverable One") + assert_equal 2, d.overhead_budgets.count + assert_equal 400, d.overhead_budget_total + + materials = d.overhead_budgets.last + assert materials + assert_equal 200, materials.budget + assert_equal 0, materials.hours + end + + should "create a new Overhead Budget record for any overhead percent" do + assert_difference("OverheadBudget.count", 5) do + RedmineContracts::BudgetPluginMigration.migrate(@data) + end + + d = Deliverable.find_by_title("Deliverable 2") + assert_equal 2, d.overhead_budgets.count + materials = d.overhead_budgets.last + assert materials + assert_equal 12 * 25 * 0.1, materials.budget + assert_equal 0, materials.hours + + end + should "append the YAML dump of the old object to the notes" do RedmineContracts::BudgetPluginMigration.migrate(@data) d = Deliverable.find_by_title("Deliverable One")