Sha256: 07374376d4254faebc1bd92504948cc5050da301f4fe36b5b6b2ddd1fc5aefb1

Contents?: true

Size: 672 Bytes

Versions: 3

Compression:

Stored size: 672 Bytes

Contents

module Billing
  class PaymentWithType < Payment
    belongs_to :payment_type, inverse_of: :payments
    
    validates_presence_of :payment_type
    validates :payment_type, inclusion: { in: :payment_types }
    
    after_initialize on: :create do
      self.payment_type = default_payment_type unless payment_type
    end
    
    def fiscal?
      payment_type.fiscal
    end
    
    def cash?
      payment_type.cash
    end
    
    private
      def default_payment_type
        if pt = billable.try(:default_payment_type)
          pt
        else
          account.payment_types.try(:first) unless account.payment_types.many?
        end
      end
    
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
billing-0.0.4b app/models/billing/payment_with_type.rb
billing-0.0.4a app/models/billing/payment_with_type.rb
billing-0.0.4 app/models/billing/payment_with_type.rb