Commit 6c9215c334b4ffb25120c9d96d51195c6a3e735c

Authored by JoenioCosta
1 parent ea6b54e3

ActionItem261: dont add the same product of enterprise twice

git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1990 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing 1 changed file with 3 additions and 4 deletions   Show diff stats
script/fbes_populate_helper.rb
... ... @@ -45,15 +45,14 @@ require File.dirname(__FILE__) + '/../config/environment'
45 45 end
46 46  
47 47 def new_ent(data, products, consumptions)
48   - posfix = ''
49 48 count = 1
50   - while Enterprise.find_by_identifier(data[:identifier] = (data[:identifier] + posfix)) do
  49 + while Enterprise.find_by_identifier(data[:identifier])
  50 + data[:identifier] = data[:identifier] + "-#{count}"
51 51 count += 1
52   - posfix = "-#{count}"
53 52 end
54 53 ent = Enterprise.create!({:environment => Environment.default}.merge(data))
55 54 products.each do |p|
56   - ent.products.create!(p)
  55 + ent.products.create!(p) unless ent.products.find(:first, :conditions => p)
57 56 end
58 57 consumptions.each do |c|
59 58 ent.consumptions.create!(c) unless ent.consumptions.find(:first, :conditions => c)
... ...