foodsoft/app/models/financial_transaction.rb

32 lines
956 B
Ruby
Raw Normal View History

2009-01-06 11:49:19 +01:00
# financial transactions are the foodcoop internal financial transactions
# only ordergroups have an account balance and are happy to transfer money
class FinancialTransaction < ApplicationRecord
belongs_to :ordergroup
2009-01-06 11:49:19 +01:00
belongs_to :user
belongs_to :financial_link
belongs_to :financial_transaction_type
validates_presence_of :amount, :note, :user_id, :ordergroup_id
validates_numericality_of :amount, greater_then: -100_000,
less_than: 100_000
scope :without_financial_link, -> { where(financial_link: nil) }
localize_input_of :amount
2009-01-06 11:49:19 +01:00
after_initialize do
initialize_financial_transaction_type
end
# Use this save method instead of simple save and after callback
def add_transaction!
ordergroup.add_financial_transaction! amount, note, user, financial_transaction_type
end
protected
def initialize_financial_transaction_type
self.financial_transaction_type ||= FinancialTransactionType.default
end
2009-01-06 11:49:19 +01:00
end