Refactor: extract method.
This commit is contained in:
@@ -74,18 +74,7 @@ module RedmineContracts
|
|||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if old_deliverable['materials'].present? && old_deliverable['materials'] > 0.0
|
convert_materials(deliverable, old_deliverable, @total)
|
||||||
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
|
|
||||||
|
|
||||||
append_old_deliverable_to_notes(old_deliverable, deliverable)
|
append_old_deliverable_to_notes(old_deliverable, deliverable)
|
||||||
|
|
||||||
deliverable.save!
|
deliverable.save!
|
||||||
@@ -113,6 +102,21 @@ module RedmineContracts
|
|||||||
contract
|
contract
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.convert_materials(deliverable, old_deliverable, total)
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
def self.append_old_deliverable_to_notes(old_deliverable, new_deliverable)
|
def self.append_old_deliverable_to_notes(old_deliverable, new_deliverable)
|
||||||
new_deliverable.notes += "Converted data:\n<pre>" + old_deliverable.pretty_inspect + "</pre>"
|
new_deliverable.notes += "Converted data:\n<pre>" + old_deliverable.pretty_inspect + "</pre>"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user