Sha256: 33b5d9a2cc4825e51f5b4d698e2ac82f1e8c9feeba7f7ce516d83f7339b667c1

Contents?: true

Size: 839 Bytes

Versions: 2

Compression:

Stored size: 839 Bytes

Contents

module SpreeAvataxOfficial
  class Transaction < ActiveRecord::Base
    SALES_ORDER               = 'SalesOrder'.freeze
    SALES_INVOICE             = 'SalesInvoice'.freeze
    RETURN_INVOICE            = 'ReturnInvoice'.freeze
    DEFAULT_ADJUSTMENT_REASON = 'Other'.freeze

    AVAILABLE_TRANSACTION_TYPES = [
      SALES_INVOICE,
      RETURN_INVOICE
    ].freeze

    belongs_to :order, class_name: 'Spree::Order'

    with_options presence: true do
      validates :code, uniqueness: true
      validates :order
      validates :transaction_type
    end

    validates :transaction_type, inclusion: { in: AVAILABLE_TRANSACTION_TYPES }

    scope :sales_invoices,  -> { with_kind(SALES_INVOICE) }
    scope :return_invoices, -> { with_kind(RETURN_INVOICE) }
    scope :with_kind,       ->(*s) { where(transaction_type: s) }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spree_avatax_official-1.8.0 app/models/spree_avatax_official/transaction.rb
spree_avatax_official-1.7.1 app/models/spree_avatax_official/transaction.rb