Sha256: dc9ff058fa40aad0cd06fc7686aa8a85e92626f6f9a4f7d427b1eb9b289fce51
Contents?: true
Size: 716 Bytes
Versions: 42
Compression:
Stored size: 716 Bytes
Contents
# frozen_string_literal: true 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
42 entries across 42 versions & 2 rubygems