Sha256: cfeaf6482ef6df0dd8f20c9207afeff155d8289dab277e0f1c1116cf9a1cfa83

Contents?: true

Size: 685 Bytes

Versions: 22

Compression:

Stored size: 685 Bytes

Contents

module Spree
  class PromotionCodeBatch < ActiveRecord::Base
    class CantProcessStartedBatch < StandardError
    end

    belongs_to :promotion, class_name: "Spree::Promotion"
    has_many :promotion_codes, class_name: "Spree::PromotionCode", dependent: :destroy

    validates :number_of_codes, numericality: { greater_than: 0 }
    validates_presence_of :base_code, :number_of_codes

    def finished?
      state == "completed"
    end

    def process
      if state == "pending"
        update!(state: "processing")
        PromotionCodeBatchJob.perform_later(self)
      else
        raise CantProcessStartedBatch.new("Batch #{id} already started")
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
solidus_core-2.5.2 app/models/spree/promotion_code_batch.rb
solidus_core-2.5.1 app/models/spree/promotion_code_batch.rb
solidus_core-2.5.0 app/models/spree/promotion_code_batch.rb
solidus_core-2.5.0.rc1 app/models/spree/promotion_code_batch.rb
solidus_core-2.5.0.beta2 app/models/spree/promotion_code_batch.rb
solidus_core-2.5.0.beta1 app/models/spree/promotion_code_batch.rb
solidus_core-2.4.2 app/models/spree/promotion_code_batch.rb
solidus_core-2.3.1 app/models/spree/promotion_code_batch.rb
solidus_core-2.4.1 app/models/spree/promotion_code_batch.rb
solidus_core-2.2.2 app/models/spree/promotion_code_batch.rb
solidus_core-2.4.0 app/models/spree/promotion_code_batch.rb
solidus_core-2.4.0.rc1 app/models/spree/promotion_code_batch.rb
solidus_core-2.4.0.beta1 app/models/spree/promotion_code_batch.rb
solidus_core-2.3.0 app/models/spree/promotion_code_batch.rb
solidus_core-2.3.0.rc3 app/models/spree/promotion_code_batch.rb
solidus_core-2.3.0.rc2 app/models/spree/promotion_code_batch.rb
solidus_core-2.3.0.rc1 app/models/spree/promotion_code_batch.rb
solidus_core-2.3.0.beta1 app/models/spree/promotion_code_batch.rb
solidus_core-2.2.1 app/models/spree/promotion_code_batch.rb
solidus_core-2.2.0 app/models/spree/promotion_code_batch.rb