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



37
38
39
# File 'app/models/financial_transaction.rb', line 37

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



33
34
35
# File 'app/models/financial_transaction.rb', line 33

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

Instance Method Details

#add_transaction!Object

Use this save method instead of simple save and after callback



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

def add_transaction!
  ordergroup.add_financial_transaction! amount, note, user, financial_transaction_type
end

#created_atObject

TODO:

rename in model, see #575



67
68
69
# File 'app/models/financial_transaction.rb', line 67

def created_at
  created_on
end

#hidden?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/models/financial_transaction.rb', line 58

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

#initialize_financial_transaction_typeObject (protected)



73
74
75
# File 'app/models/financial_transaction.rb', line 73

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

#ordergroup_nameObject



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

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

#revert!(user) ⇒ Object



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

def revert!(user)
  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