app/models/billing/payment.rb in billing-0.0.4 vs app/models/billing/payment.rb in billing-0.0.5a

- old
+ new

@@ -1,50 +1,47 @@ module Billing class Payment < ActiveRecord::Base PAYMENT_WITH_TYPE = 'Billing::PaymentWithType'.freeze PAYMENT_EXTERNAL = 'Billing::PaymentExternal'.freeze PAYPAL_EXPRESS = 'Billing::PaypalExpress'.freeze - PAYMENT_MODELS = [PAYMENT_WITH_TYPE, PAYMENT_EXTERNAL, PAYPAL_EXPRESS].freeze + ROOM_TRANSFER = 'Billing::RoomTransfer'.freeze + PAYMENT_MODELS = [PAYMENT_WITH_TYPE, PAYMENT_EXTERNAL, PAYPAL_EXPRESS, ROOM_TRANSFER].freeze - include AccountItem + include BillItem attr_writer :origin attr_accessor :origin_id monetize :value_cents - belongs_to :account, inverse_of: :payments, validate: true + belongs_to :bill, inverse_of: :payments, validate: true scope :in_period, lambda {|from, to| where(created_at: from..to) } - scope :for_report, -> { joins(:account).where(billing_accounts: { balance_cents: 0 ,report_id: nil }) } + scope :for_report, -> { joins(:bill).where(billing_bills: { balance_cents: 0 ,report_id: nil }) } if defined? Extface belongs_to :extface_job, class_name: 'Extface::Job' end - delegate :billable, to: :account + delegate :billable, to: :bill, allow_nil: true validates_numericality_of :value, greater_than_or_equal_to: 0 validates :type, inclusion: { in: PAYMENT_MODELS } after_initialize on: :create do - self.value = -account.try(:balance) if value.zero? + self.value = -bill.try(:balance) if bill && value.zero? end - before_validation do - account.origin = origin unless account.origin and account.payments.many? - end - def fiscal?; false; end def cash?; false; end def external?; false; end def origin @origin || origins.find_by_id(@origin_id) end private class << self - def args(*args) + def wild_args(*args) h = {} case when args.blank? || args.first.kind_of?(Hash) then args.blank? ? h : h.merge(*args) when args.first.kind_of?(String) then #TODO parse