Skip to content

Instantly share code, notes, and snippets.

@rvalyi
Created July 23, 2010 19:11
Show Gist options
  • Save rvalyi/487895 to your computer and use it in GitHub Desktop.
Save rvalyi/487895 to your computer and use it in GitHub Desktop.
p_id=ProjectProject.create(:name => "Alarme Perimetral").id
s="""Lançamento de cabos
Fixação de caixas de Proteção ou Domes
Instalação das câmeras e fontes
Montagem do computador e ligação das câmeras
Testes finais"""
t=s.split("\n")
pred_id = []
t.each do |name|
pred_id = [ProjectPhase.create(:name => name, :project_id => p_id, :duration => rand(5)+2, :previous_phase_ids => pred_id).id]
end
project_ids = ProjectProject.search([['state', '=', 'template']])
rec_ids=ResourceResource.search([['id', '>', 3],['template_id', '=', false]])
project_ids.each do |id|
project = ProjectProject.find(id)
project.phase_ids.each do |phase|
phase.resource_ids = []
(rand(5) + 1).times do
rec_id = rec_ids[rand(rec_ids.size) - 0]
phase.resource_ids << ProjectResourceAllocation.new(:resource_id => rec_id, :resource_template_id => rec_id, :phase_id => phase.id)
end
p "phase.name", phase.resource_ids
phase.save
end
end
project_ids = ProjectProject.search([['state', '=', 'template']])
prod_ids=ProductProduct.search([['type', '=', 'product']])
project_ids.each do |id|
project = ProjectProject.find(id)
project.phase_ids.each do |phase|
phase.product_ids = []
(rand(5) + 1).times do
rec_id = rec_ids[rand(rec_ids.size) - 0]
phase.product_ids << ProjectProductAllocation.new(:product_id => rec_id, :product_qty => rand(9)+1, :phase_id => phase.id)
end
p "phase.name", phase.product_ids
phase.save
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment