mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
* add kind to transaction model * Basic transfer creator * Fix method naming conflict * Creator form pattern * Remove stale methods * Tweak migration * Remove BaseQuery, write entire query in each class for clarity * Query optimizations * Remove unused exchange rate query lines * Remove temporary cache-warming strategy * Fix test * Update transaction search * Decouple transactions endpoint from IncomeStatement * Clean up transactions controller * Update cursor rules * Cleanup comments, logic in search * Fix totals logic on transactions view * Fix pagination * Optimize search totals query * Default to last 30 days on transactions page if no filters * Decouple transactions list from transfer details * Revert transfer route * Migration reset * Bundle update * Fix matching logic, tests * Remove unused code
34 lines
1.2 KiB
Ruby
34 lines
1.2 KiB
Ruby
class Transaction < ApplicationRecord
|
|
include Entryable, Transferable, Ruleable
|
|
|
|
belongs_to :category, optional: true
|
|
belongs_to :merchant, optional: true
|
|
|
|
has_many :taggings, as: :taggable, dependent: :destroy
|
|
has_many :tags, through: :taggings
|
|
|
|
accepts_nested_attributes_for :taggings, allow_destroy: true
|
|
|
|
enum :kind, {
|
|
standard: "standard", # A regular transaction, included in budget analytics
|
|
funds_movement: "funds_movement", # Movement of funds between accounts, excluded from budget analytics
|
|
cc_payment: "cc_payment", # A CC payment, excluded from budget analytics (CC payments offset the sum of expense transactions)
|
|
loan_payment: "loan_payment", # A payment to a Loan account, treated as an expense in budgets
|
|
one_time: "one_time" # A one-time expense/income, excluded from budget analytics
|
|
}
|
|
|
|
# Overarching grouping method for all transfer-type transactions
|
|
def transfer?
|
|
funds_movement? || cc_payment? || loan_payment?
|
|
end
|
|
|
|
def set_category!(category)
|
|
if category.is_a?(String)
|
|
category = entry.account.family.categories.find_or_create_by!(
|
|
name: category
|
|
)
|
|
end
|
|
|
|
update!(category: category)
|
|
end
|
|
end
|