Sha256: 7fa07c17633fa3631521360c0c2df48d96f3d6a5c61b14f46caea9a5894c6e3f

Contents?: true

Size: 756 Bytes

Versions: 91

Compression:

Stored size: 756 Bytes

Contents

# frozen_string_literal: true

module Spree
  class Reimbursement < Spree::Base
    class Credit < Spree::Base
      class_attribute :default_creditable_class
      self.default_creditable_class = Spree::StoreCredit

      belongs_to :reimbursement, inverse_of: :credits, optional: true
      belongs_to :creditable, polymorphic: true, optional: true

      validates :creditable, presence: true

      class << self
        def total_amount_reimbursed_for(reimbursement)
          reimbursement.credits.to_a.sum(&:amount)
        end
      end

      def description
        creditable.class.name.demodulize
      end

      def display_amount
        Spree::Money.new(amount, { currency: creditable.try(:currency) || "USD" })
      end
    end
  end
end

Version data entries

91 entries across 91 versions & 1 rubygems

Version Path
solidus_core-4.4.2 app/models/spree/reimbursement/credit.rb
solidus_core-4.4.1 app/models/spree/reimbursement/credit.rb
solidus_core-4.4.0 app/models/spree/reimbursement/credit.rb
solidus_core-4.3.4 app/models/spree/reimbursement/credit.rb
solidus_core-4.2.4 app/models/spree/reimbursement/credit.rb
solidus_core-4.1.5 app/models/spree/reimbursement/credit.rb
solidus_core-4.3.3 app/models/spree/reimbursement/credit.rb
solidus_core-4.3.2 app/models/spree/reimbursement/credit.rb
solidus_core-4.1.4 app/models/spree/reimbursement/credit.rb
solidus_core-4.3.1 app/models/spree/reimbursement/credit.rb
solidus_core-4.3.0 app/models/spree/reimbursement/credit.rb
solidus_core-4.2.3 app/models/spree/reimbursement/credit.rb
solidus_core-4.1.3 app/models/spree/reimbursement/credit.rb
solidus_core-4.0.4 app/models/spree/reimbursement/credit.rb
solidus_core-3.4.6 app/models/spree/reimbursement/credit.rb
solidus_core-4.0.3 app/models/spree/reimbursement/credit.rb
solidus_core-4.1.2 app/models/spree/reimbursement/credit.rb
solidus_core-4.2.2 app/models/spree/reimbursement/credit.rb
solidus_core-3.4.5 app/models/spree/reimbursement/credit.rb
solidus_core-4.2.1 app/models/spree/reimbursement/credit.rb