Class: FinancialTransaction
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- FinancialTransaction
- 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
- .ransackable_associations(_auth_object = nil) ⇒ Object
- .ransackable_attributes(_auth_object = nil) ⇒ Object
Instance Method Summary collapse
- #created_at ⇒ Object
- #hidden? ⇒ Boolean
- #initialize_financial_transaction_type ⇒ Object protected
- #ordergroup_name ⇒ Object
- #revert!(user) ⇒ Object
Methods included from LocalizeInput
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_at ⇒ Object
70 71 72 |
# File 'app/models/financial_transaction.rb', line 70 def created_at created_on end |
#hidden? ⇒ Boolean
61 62 63 |
# File 'app/models/financial_transaction.rb', line 61 def hidden? reverts.present? || reverted_by.present? end |
#initialize_financial_transaction_type ⇒ Object (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_name ⇒ Object
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 |