From c17e8eaf1b845d711e2a9b2f49bc89c961dab668 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Thu, 12 Aug 2010 08:11:11 -0700 Subject: [PATCH] [#4409] Old HourlyDeliverables should be converted over to FixedDeliverables. --- .../budget_plugin_migration.rb | 18 +++++++++------- .../budget_plugin_migration_test.rb | 21 +++++++++++++++---- 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/redmine_contracts/budget_plugin_migration.rb b/lib/redmine_contracts/budget_plugin_migration.rb index af364a2..6f5f995 100644 --- a/lib/redmine_contracts/budget_plugin_migration.rb +++ b/lib/redmine_contracts/budget_plugin_migration.rb @@ -45,31 +45,33 @@ module RedmineContracts :end_date => old_deliverable['due'], :notes => old_deliverable['description'] ) - deliverable.type = old_deliverable['type'] + # All deliverables are converted over to FixedDeliverable + deliverable.type = 'FixedDeliverable' project = Project.find(old_deliverable['project_id']) contract = Contract.find_by_project_id(project.id) contract ||= create_new_contract(old_deliverable) deliverable.contract = contract deliverable.manager = project.users.first - + deliverable.total = old_deliverable['budget'] + case old_deliverable['type'] when 'FixedDeliverable' - @total = deliverable.total = old_deliverable['fixed_cost'] + @total_cost = old_deliverable['fixed_cost'] when 'HourlyDeliverable' - @total = old_deliverable['total_hours'].to_f * old_deliverable['cost_per_hour'].to_f + @total_cost = old_deliverable['total_hours'].to_f * old_deliverable['cost_per_hour'].to_f if old_deliverable['total_hours'].present? || old_deliverable['cost_per_hour'].present? deliverable.labor_budgets << LaborBudget.new(:deliverable => deliverable, - :budget => @total, + :budget => @total_cost, :hours => old_deliverable['total_hours']) end else - @total = 0 + @total_cost = 0 end - convert_overhead(deliverable, old_deliverable, @total) - convert_materials(deliverable, old_deliverable, @total) + convert_overhead(deliverable, old_deliverable, @total_cost) + convert_materials(deliverable, old_deliverable, @total_cost) append_old_deliverable_to_notes(old_deliverable, deliverable) deliverable.save! diff --git a/test/integration/budget_plugin_migration_test.rb b/test/integration/budget_plugin_migration_test.rb index 0734dbc..86a9112 100644 --- a/test/integration/budget_plugin_migration_test.rb +++ b/test/integration/budget_plugin_migration_test.rb @@ -35,8 +35,8 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest should "create a new Deliverable for each old Deliverable" do assert_difference("Deliverable.count", 3) do - assert_difference("HourlyDeliverable.count", 2) do - assert_difference("FixedDeliverable.count", 1) do + assert_difference("HourlyDeliverable.count", 0) do + assert_difference("FixedDeliverable.count", 3) do RedmineContracts::BudgetPluginMigration.migrate(@data) end end @@ -152,15 +152,28 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest end context "converting Fixed Deliverables" do - should "convert fixed_cost to total" do + should "convert the budget field to total" do RedmineContracts::BudgetPluginMigration.migrate(@data) d = FixedDeliverable.find_by_title("Version 1.0") - assert_equal 30_000, d.total + assert_equal 93_000, d.total end end context "converting Hourly Deliverables" do + should "convert over into Fixed Deliverables" do + assert_difference("FixedDeliverable.count",3) do + RedmineContracts::BudgetPluginMigration.migrate(@data) + end + end + + should "convert the old 'budget' field into the total" do + RedmineContracts::BudgetPluginMigration.migrate(@data) + + assert_equal 5600, FixedDeliverable.find_by_title("Deliverable One").total + assert_equal 900, FixedDeliverable.find_by_title("Deliverable 2").total + end + should "create a new Labor Budget" do assert_difference("LaborBudget.count", 2) do RedmineContracts::BudgetPluginMigration.migrate(@data)