From cd382fd78498f75c11596009cc32d06ab8bd5a44 Mon Sep 17 00:00:00 2001 From: Eric Davis Date: Thu, 23 Sep 2010 13:30:44 -0700 Subject: [PATCH] [#4558] Allow overriding the Contract account executive and Deliverable manager when converting --- .../budget_plugin_migration.rb | 21 +++++++++- lib/tasks/budget_plugin_migration.rake | 2 + .../budget_plugin_migration_test.rb | 38 ++++++++++++++++++- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/lib/redmine_contracts/budget_plugin_migration.rb b/lib/redmine_contracts/budget_plugin_migration.rb index 50790cd..22040e7 100644 --- a/lib/redmine_contracts/budget_plugin_migration.rb +++ b/lib/redmine_contracts/budget_plugin_migration.rb @@ -29,8 +29,25 @@ module RedmineContracts end # * old_data - YAML string of deliverables to migrate + # + # @param [Hash] options the options to migrate with + # @option options [String] :contract_rate the contract rate to use. Defaults to 150.0 + # @option options [String] :account_executive the id or login of the user + # to use for the contract account executive + # Defaults to the first user on the project. + # @option options [String] :deliverable_manager the id or login of the user + # to use for the deliverables manager + # Defaults to the first user on the project. 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? + user = User.find_by_login(options[:account_executive]) + user ||= User.find_by_id(options[:account_executive]) + end + @deliverable_manager = if options[:deliverable_manager].present? + user = User.find_by_login(options[:deliverable_manager]) + user ||= User.find_by_id(options[:deliverable_manager]) + end @@data = YAML.load(old_data) @@ -52,7 +69,7 @@ module RedmineContracts contract ||= create_new_contract(old_deliverable) deliverable.contract = contract - deliverable.manager = project.users.first + deliverable.manager = @deliverable_manager || project.users.first deliverable.total = old_deliverable['budget'] case old_deliverable['type'] @@ -109,7 +126,7 @@ module RedmineContracts :start_date => old_deliverable['due'], :end_date => old_deliverable['due']) do |c| c.project = project - c.account_executive = project.users.first + c.account_executive = @account_executive || project.users.first c.start_date ||= Date.today c.end_date ||= Date.today c.billable_rate = @contract_rate diff --git a/lib/tasks/budget_plugin_migration.rake b/lib/tasks/budget_plugin_migration.rake index df5580e..62b0b73 100644 --- a/lib/tasks/budget_plugin_migration.rake +++ b/lib/tasks/budget_plugin_migration.rake @@ -3,6 +3,8 @@ namespace :redmine_contracts do task :budget_migration => :environment do options = {} options[:contract_rate] = ENV['contract_rate'] + options[:account_executive] = ENV['account_executive'] + options[:deliverable_manager] = ENV['deliverable_manager'] RedmineContracts::BudgetPluginMigration.check_for_installed_budget_plugin data = RedmineContracts::BudgetPluginMigration.export_data diff --git a/test/integration/budget_plugin_migration_test.rb b/test/integration/budget_plugin_migration_test.rb index 20884c7..2954196 100644 --- a/test/integration/budget_plugin_migration_test.rb +++ b/test/integration/budget_plugin_migration_test.rb @@ -19,10 +19,13 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest Project.stubs(:find_by_id).with(1).returns(@project_one) Project.stubs(:find_by_id).with(2).returns(@project_one) - @manager = User.generate! @role = Role.generate! + @manager = User.generate! User.add_to_project(@manager, @project_one, @role) User.add_to_project(@manager, @project_two, @role) + @other_user = User.generate! + User.add_to_project(@other_user, @project_one, @role) + User.add_to_project(@other_user, @project_two, @role) end @@ -67,6 +70,27 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest assert_equal 100.5, @project_one.reload.contracts.first.billable_rate assert_equal 100.5, @project_two.reload.contracts.first.billable_rate end + + should "pick the first project member as the account executive" do + RedmineContracts::BudgetPluginMigration.migrate(@data) + + assert_equal @manager, @project_one.reload.contracts.first.account_executive + assert_equal @manager, @project_two.reload.contracts.first.account_executive + end + + should "allow overriding the account executive by login" do + RedmineContracts::BudgetPluginMigration.migrate(@data, :account_executive => @other_user.login) + + assert_equal @other_user, @project_one.reload.contracts.first.account_executive + assert_equal @other_user, @project_two.reload.contracts.first.account_executive + end + + should "allow overriding the account executive by id" do + RedmineContracts::BudgetPluginMigration.migrate(@data, :account_executive => @other_user.id) + + assert_equal @other_user, @project_one.reload.contracts.first.account_executive + assert_equal @other_user, @project_two.reload.contracts.first.account_executive + end end should "enable the contracts plugin for each project with a contract" do @@ -84,6 +108,18 @@ class BudgetPluginMigrationTest < ActionController::IntegrationTest assert_equal [@manager, @manager, @manager], Deliverable.all.collect(&:manager) end + should "allow overriding the deliverable manager by login" do + RedmineContracts::BudgetPluginMigration.migrate(@data, :deliverable_manager => @other_user.login) + + assert_equal [@other_user, @other_user, @other_user], Deliverable.all.collect(&:manager) + end + + should "allow overriding the deliverable manager by id" do + RedmineContracts::BudgetPluginMigration.migrate(@data, :deliverable_manager => @other_user.id) + + 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)