mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Refactor Plaid transaction type mapping and improve label handling
- Updated `PLAID_TYPE_TO_LABEL` in `TransactionsProcessor` to consolidate labels ("Cancel" and "Cash" now mapped to "Other").
- Adjusted `label_from_plaid_type` to return "Other" as the default fallback.
- Enhanced tests to include additional valid activity labels and ensure label consistency.
- Minor fixes to locale keys for transaction views.
This commit is contained in:
@@ -2,11 +2,12 @@ class PlaidAccount::Investments::TransactionsProcessor
|
||||
SecurityNotFoundError = Class.new(StandardError)
|
||||
|
||||
# Map Plaid investment transaction types to activity labels
|
||||
# All values must be valid Transaction::ACTIVITY_LABELS
|
||||
PLAID_TYPE_TO_LABEL = {
|
||||
"buy" => "Buy",
|
||||
"sell" => "Sell",
|
||||
"cancel" => "Cancelled",
|
||||
"cash" => "Cash",
|
||||
"cancel" => "Other",
|
||||
"cash" => "Other",
|
||||
"fee" => "Fee",
|
||||
"transfer" => "Transfer",
|
||||
"dividend" => "Dividend",
|
||||
@@ -92,7 +93,7 @@ class PlaidAccount::Investments::TransactionsProcessor
|
||||
|
||||
def label_from_plaid_type(transaction)
|
||||
plaid_type = transaction["type"]&.downcase
|
||||
PLAID_TYPE_TO_LABEL[plaid_type] || plaid_type&.titleize
|
||||
PLAID_TYPE_TO_LABEL[plaid_type] || "Other"
|
||||
end
|
||||
|
||||
def transactions
|
||||
|
||||
@@ -17,7 +17,7 @@ class Transaction < ApplicationRecord
|
||||
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
|
||||
investment_contribution: "investment_contribution" # Transfer to investment/crypto account, included in budget as investment expense
|
||||
investment_contribution: "investment_contribution" # Transfer to investment/crypto account, excluded from budget analytics
|
||||
}
|
||||
|
||||
# All valid investment activity labels (for UI dropdown)
|
||||
|
||||
Reference in New Issue
Block a user