Commit 6c9215c334b4ffb25120c9d96d51195c6a3e735c
1 parent
ea6b54e3
Exists in
master
and in
29 other branches
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,15 +45,14 @@ require File.dirname(__FILE__) + '/../config/environment' | ||
45 | end | 45 | end |
46 | 46 | ||
47 | def new_ent(data, products, consumptions) | 47 | def new_ent(data, products, consumptions) |
48 | - posfix = '' | ||
49 | count = 1 | 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 | count += 1 | 51 | count += 1 |
52 | - posfix = "-#{count}" | ||
53 | end | 52 | end |
54 | ent = Enterprise.create!({:environment => Environment.default}.merge(data)) | 53 | ent = Enterprise.create!({:environment => Environment.default}.merge(data)) |
55 | products.each do |p| | 54 | products.each do |p| |
56 | - ent.products.create!(p) | 55 | + ent.products.create!(p) unless ent.products.find(:first, :conditions => p) |
57 | end | 56 | end |
58 | consumptions.each do |c| | 57 | consumptions.each do |c| |
59 | ent.consumptions.create!(c) unless ent.consumptions.find(:first, :conditions => c) | 58 | ent.consumptions.create!(c) unless ent.consumptions.find(:first, :conditions => c) |