diff --git a/legacy_promotions/app/models/spree/promotion_code/batch_builder.rb b/legacy_promotions/app/models/spree/promotion_code/batch_builder.rb index a6f321fa91..422690d32e 100644 --- a/legacy_promotions/app/models/spree/promotion_code/batch_builder.rb +++ b/legacy_promotions/app/models/spree/promotion_code/batch_builder.rb @@ -41,15 +41,15 @@ def generate_random_codes new_codes = Array.new(max_codes_to_generate) { generate_random_code }.uniq codes_for_current_batch = get_unique_codes(new_codes) - codes_for_current_batch = codes_for_current_batch.map do |value| + codes_for_current_batch.filter! do |value| Spree::PromotionCode.create!( value: value, promotion: promotion, promotion_code_batch: promotion_code_batch ) rescue ActiveRecord::RecordInvalid - nil - end.compact + false + end created_codes += codes_for_current_batch.size end end