1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-05 05:25:24 +02:00

Fix transaction filters when transfers are present (#1986)
Some checks failed
Publish Docker image / ci (push) Has been cancelled
Publish Docker image / Build docker image (push) Has been cancelled

* Proper filtering of transfers in search

* Fix transaction search
This commit is contained in:
Zach Gollwitzer 2025-03-11 15:38:45 -04:00 committed by GitHub
parent ed55ef624b
commit dd75cadebc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 96 additions and 45 deletions

View file

@ -1,6 +1,24 @@
module Account::EntriesHelper
def entries_by_date(entries, totals: false)
entries.group_by(&:date).map do |date, grouped_entries|
transfer_groups = entries.group_by do |entry|
# Only check for transfer if it's a transaction
next nil unless entry.entryable_type == "Account::Transaction"
entry.entryable.transfer&.id
end
# For a more intuitive UX, we do not want to show the same transfer twice in the list
deduped_entries = transfer_groups.flat_map do |transfer_id, grouped_entries|
if transfer_id.nil? || grouped_entries.size == 1
grouped_entries
else
grouped_entries.reject do |e|
e.entryable_type == "Account::Transaction" &&
e.entryable.transfer_as_inflow.present?
end
end
end
deduped_entries.group_by(&:date).map do |date, grouped_entries|
content = capture do
yield grouped_entries
end