mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-07 06:25:19 +02:00
Handle holding quantity generation for reverse syncs correctly when not all holdings are generated for current day (#2417)
* Handle reverse calculator starting portfolio generation correctly * Fix current_holdings to handle different dates and hide zero quantities - Use DISTINCT ON to get most recent holding per security instead of assuming same date - Filter out zero quantity holdings from UI display - Maintain cash display regardless of zero balance - Use single efficient query with proper Rails syntax * Continue to process holdings even if one is not resolvable * Lint fixes
This commit is contained in:
parent
e60b5df442
commit
8db95623cf
8 changed files with 281 additions and 39 deletions
|
@ -8,11 +8,14 @@ class PlaidAccount::Investments::HoldingsProcessor
|
|||
holdings.each do |plaid_holding|
|
||||
resolved_security_result = security_resolver.resolve(plaid_security_id: plaid_holding["security_id"])
|
||||
|
||||
return unless resolved_security_result.security.present?
|
||||
next unless resolved_security_result.security.present?
|
||||
|
||||
security = resolved_security_result.security
|
||||
holding_date = plaid_holding["institution_price_as_of"] || Date.current
|
||||
|
||||
holding = account.holdings.find_or_initialize_by(
|
||||
security: resolved_security_result.security,
|
||||
date: Date.current,
|
||||
security: security,
|
||||
date: holding_date,
|
||||
currency: plaid_holding["iso_currency_code"]
|
||||
)
|
||||
|
||||
|
@ -22,7 +25,15 @@ class PlaidAccount::Investments::HoldingsProcessor
|
|||
amount: plaid_holding["quantity"] * plaid_holding["institution_price"]
|
||||
)
|
||||
|
||||
holding.save!
|
||||
ActiveRecord::Base.transaction do
|
||||
holding.save!
|
||||
|
||||
# Delete all holdings for this security after the institution price date
|
||||
account.holdings
|
||||
.where(security: security)
|
||||
.where("date > ?", holding_date)
|
||||
.destroy_all
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue