mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-04 13:05:19 +02:00
Add scope to filter transactions from active accounts (#1810)
* Add scope to filter transactions from active accounts * Add test for transfer match candidates with active accounts * Refactor active account filtering for transactions and entries
This commit is contained in:
parent
cf014bc24f
commit
4aba9d1c0b
5 changed files with 69 additions and 1 deletions
|
@ -7,7 +7,7 @@ class TransactionsController < ApplicationController
|
|||
|
||||
def index
|
||||
@q = search_params
|
||||
search_query = Current.family.transactions.search(@q)
|
||||
search_query = Current.family.transactions.search(@q).active
|
||||
|
||||
set_focused_record(search_query, params[:focused_record_id], default_per_page: 50)
|
||||
|
||||
|
|
|
@ -184,6 +184,8 @@ class Account < ApplicationRecord
|
|||
.joins("JOIN accounts inflow_accounts ON inflow_accounts.id = inflow_candidates.account_id")
|
||||
.joins("JOIN accounts outflow_accounts ON outflow_accounts.id = outflow_candidates.account_id")
|
||||
.where("inflow_accounts.family_id = ? AND outflow_accounts.family_id = ?", self.family_id, self.family_id)
|
||||
.where("inflow_accounts.is_active = true AND inflow_accounts.scheduled_for_deletion = false")
|
||||
.where("outflow_accounts.is_active = true AND outflow_accounts.scheduled_for_deletion = false")
|
||||
.where("inflow_candidates.entryable_type = 'Account::Transaction' AND outflow_candidates.entryable_type = 'Account::Transaction'")
|
||||
.where(existing_transfers: { id: nil })
|
||||
.order("date_diff ASC") # Closest matches first
|
||||
|
|
|
@ -24,6 +24,10 @@ class Account::Entry < ApplicationRecord
|
|||
)
|
||||
}
|
||||
|
||||
scope :active, -> {
|
||||
joins(:account).where(accounts: { is_active: true, scheduled_for_deletion: false })
|
||||
}
|
||||
|
||||
scope :reverse_chronological, -> {
|
||||
order(
|
||||
date: :desc,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue