Refactor: extract method.

This commit is contained in:
Eric Davis
2010-07-19 08:41:25 -07:00
parent 4f9ee03fb5
commit 435a75d2c7
@@ -40,19 +40,9 @@ module RedmineContracts
:notes => old_deliverable['description']
)
deliverable.type = old_deliverable['type']
project = Project.find(old_deliverable['project_id'])
contract = Contract.find_by_project_id(project.id)
if contract.nil?
contract = Contract.new(:name => 'Converted Contract',
:start_date => old_deliverable['due'],
:end_date => old_deliverable['due'])
contract.project = project
contract.account_executive = project.users.first
contract.save!
end
contract ||= create_new_contract(old_deliverable)
deliverable.contract = contract
deliverable.manager = project.users.first
@@ -106,5 +96,20 @@ module RedmineContracts
def self.data
@@data
end
private
def self.create_new_contract(old_deliverable)
project = Project.find(old_deliverable['project_id'])
contract = Contract.new(:name => 'Converted Contract',
:start_date => old_deliverable['due'],
:end_date => old_deliverable['due'])
contract.project = project
contract.account_executive = project.users.first
contract.save!
contract
end
end
end