Class: FinancialTransaction

Inherits:
ApplicationRecord show all
Includes:
LocalizeInput
Defined in:
app/models/financial_transaction.rb

Overview

financial transactions are the foodcoop internal financial transactions only ordergroups have an account balance and are happy to transfer money

Class Method Summary collapse

Instance Method Summary collapse

Methods included from LocalizeInput

parse

Class Method Details

.ransackable_associations(_auth_object = nil) ⇒ Object



43
44
45
# File 'app/models/financial_transaction.rb', line 43

def self.ransackable_associations(_auth_object = nil)
  %w[] # none, and certainly not user until we've secured that more
end

.ransackable_attributes(_auth_object = nil) ⇒ Object



39
40
41
# File 'app/models/financial_transaction.rb', line 39

def self.ransackable_attributes(_auth_object = nil)
  %w[id amount note created_on user_id]
end

Instance Method Details

#created_atObject



70
71
72
# File 'app/models/financial_transaction.rb', line 70

def created_at
  created_on
end

#hidden?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/financial_transaction.rb', line 61

def hidden?
  reverts.present? || reverted_by.present?
end

#initialize_financial_transaction_typeObject (protected)



76
77
78
# File 'app/models/financial_transaction.rb', line 76

def initialize_financial_transaction_type
  self.financial_transaction_type ||= FinancialTransactionType.default
end

#ordergroup_nameObject



65
66
67
# File 'app/models/financial_transaction.rb', line 65

def ordergroup_name
  ordergroup ? ordergroup.name : I18n.t('model.financial_transaction.foodcoop_name')
end

#revert!(user) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/models/financial_transaction.rb', line 47

def revert!(user)
  raise 'Pending Transaction cannot be reverted' if amount.nil?

  transaction do
    update_attribute :financial_link, FinancialLink.new
    rt = dup
    rt.amount = -rt.amount
    rt.reverts = self
    rt.user = user
    rt.save!
    ordergroup.update_balance! if ordergroup
  end
end