Refactor: extract method.
This commit is contained in:
1 parent
4f9ee03fb5
commit
435a75d2c7
1 file changed
+16
-11
@@ -40,19 +40,9 @@ module RedmineContracts
|
|||||||
:notes => old_deliverable['description']
|
:notes => old_deliverable['description']
|
||||||
)
|
)
|
||||||
deliverable.type = old_deliverable['type']
|
deliverable.type = old_deliverable['type']
|
||||||
|
|
||||||
project = Project.find(old_deliverable['project_id'])
|
project = Project.find(old_deliverable['project_id'])
|
||||||
contract = Contract.find_by_project_id(project.id)
|
contract = Contract.find_by_project_id(project.id)
|
||||||
if contract.nil?
|
contract ||= create_new_contract(old_deliverable)
|
||||||
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
|
|
||||||
|
|
||||||
deliverable.contract = contract
|
deliverable.contract = contract
|
||||||
deliverable.manager = project.users.first
|
deliverable.manager = project.users.first
|
||||||
@@ -106,5 +96,20 @@ module RedmineContracts
|
|||||||
def self.data
|
def self.data
|
||||||
@@data
|
@@data
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
Reference in new issue
Block a user