mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 05:25:24 +02:00
Preserve original transaction names when enriching (#1556)
* Preserve original transaction name * Remove stale method * Fix tests
This commit is contained in:
parent
68617514b0
commit
7be6a372bf
22 changed files with 100 additions and 76 deletions
|
@ -50,7 +50,7 @@ class Account::DataEnricher
|
|||
category.save! if category.present?
|
||||
entry.update!(
|
||||
enriched_at: Time.current,
|
||||
name: entry.enriched_at.nil? && info.name ? info.name : entry.name,
|
||||
enriched_name: info.name,
|
||||
entryable_attributes: entryable_attributes
|
||||
)
|
||||
end
|
||||
|
|
|
@ -10,7 +10,7 @@ class Account::Entry < ApplicationRecord
|
|||
delegated_type :entryable, types: Account::Entryable::TYPES, dependent: :destroy
|
||||
accepts_nested_attributes_for :entryable
|
||||
|
||||
validates :date, :amount, :currency, presence: true
|
||||
validates :date, :name, :amount, :currency, presence: true
|
||||
validates :date, uniqueness: { scope: [ :account_id, :entryable_type ] }, if: -> { account_valuation? }
|
||||
validates :date, comparison: { greater_than: -> { min_supported_date } }
|
||||
|
||||
|
@ -47,14 +47,6 @@ class Account::Entry < ApplicationRecord
|
|||
account.sync_later(start_date: sync_start_date)
|
||||
end
|
||||
|
||||
def inflow?
|
||||
amount <= 0 && account_transaction?
|
||||
end
|
||||
|
||||
def outflow?
|
||||
amount > 0 && account_transaction?
|
||||
end
|
||||
|
||||
def entryable_name_short
|
||||
entryable_type.demodulize.underscore
|
||||
end
|
||||
|
@ -63,6 +55,10 @@ class Account::Entry < ApplicationRecord
|
|||
Account::BalanceTrendCalculator.new(self, entries, balances).trend
|
||||
end
|
||||
|
||||
def display_name
|
||||
enriched_name.presence || name
|
||||
end
|
||||
|
||||
class << self
|
||||
# arbitrary cutoff date to avoid expensive sync operations
|
||||
def min_supported_date
|
||||
|
|
|
@ -11,7 +11,8 @@ class Account::Syncer
|
|||
update_account_info(balances, holdings) unless account.plaid_account_id.present?
|
||||
convert_records_to_family_currency(balances, holdings) unless account.currency == account.family.currency
|
||||
|
||||
if account.family.data_enrichment_enabled?
|
||||
# Enrich if user opted in or if we're syncing transactions from a Plaid account
|
||||
if account.family.data_enrichment_enabled? || account.plaid_account_id.present?
|
||||
account.enrich_data_later
|
||||
else
|
||||
Rails.logger.info("Data enrichment is disabled, skipping enrichment for account #{account.id}")
|
||||
|
|
|
@ -26,11 +26,6 @@ class Account::Trade < ApplicationRecord
|
|||
qty > 0
|
||||
end
|
||||
|
||||
def name
|
||||
prefix = sell? ? "Sell " : "Buy "
|
||||
prefix + "#{qty.abs} shares of #{security.ticker}"
|
||||
end
|
||||
|
||||
def unrealized_gain_loss
|
||||
return nil if sell?
|
||||
current_price = security.current_price
|
||||
|
|
|
@ -31,7 +31,11 @@ class Account::TradeBuilder
|
|||
end
|
||||
|
||||
def build_trade
|
||||
prefix = type == "sell" ? "Sell " : "Buy "
|
||||
trade_name = prefix + "#{qty.to_i.abs} shares of #{security.ticker}"
|
||||
|
||||
account.entries.new(
|
||||
name: trade_name,
|
||||
date: date,
|
||||
amount: signed_amount,
|
||||
currency: currency,
|
||||
|
|
|
@ -48,10 +48,6 @@ class Account::Transaction < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def name
|
||||
entry.name || (entry.amount.positive? ? "Expense" : "Income")
|
||||
end
|
||||
|
||||
def eod_balance
|
||||
entry.amount_money
|
||||
end
|
||||
|
|
|
@ -33,11 +33,11 @@ class Account::Transfer < ApplicationRecord
|
|||
end
|
||||
|
||||
def inflow_transaction
|
||||
entries.find { |e| e.inflow? }
|
||||
entries.find { |e| e.amount.negative? }
|
||||
end
|
||||
|
||||
def outflow_transaction
|
||||
entries.find { |e| e.outflow? }
|
||||
entries.find { |e| e.amount.positive? }
|
||||
end
|
||||
|
||||
def update_entries!(params)
|
||||
|
|
|
@ -10,8 +10,4 @@ class Account::Valuation < ApplicationRecord
|
|||
false
|
||||
end
|
||||
end
|
||||
|
||||
def name
|
||||
"Balance update"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue