[#4409] Old HourlyDeliverables should be converted over to FixedDeliverables.
This commit is contained in:
@@ -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!
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user