mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-10 07:55:21 +02:00
Revert transfer route
This commit is contained in:
parent
56d97a92db
commit
7e8b72fcc7
4 changed files with 13 additions and 34 deletions
|
@ -50,15 +50,11 @@ class TransfersController < ApplicationController
|
|||
|
||||
private
|
||||
def set_transfer
|
||||
if params[:transaction_id]
|
||||
@transfer = Current.family.transactions.find(params[:transaction_id]).transfer
|
||||
else
|
||||
# Finds the transfer and ensures the family owns it
|
||||
@transfer = Transfer
|
||||
.where(id: params[:id])
|
||||
.where(inflow_transaction_id: Current.family.transactions.select(:id))
|
||||
.first
|
||||
end
|
||||
# Finds the transfer and ensures the family owns it
|
||||
@transfer = Transfer
|
||||
.where(id: params[:id])
|
||||
.where(inflow_transaction_id: Current.family.transactions.select(:id))
|
||||
.first
|
||||
end
|
||||
|
||||
def transfer_params
|
||||
|
|
|
@ -1,35 +1,19 @@
|
|||
module EntriesHelper
|
||||
def entries_by_date(entries, totals: false)
|
||||
# Group transactions that might be transfers by their matching criteria
|
||||
# Use amount, date, and currency to identify potential transfer pairs
|
||||
transfer_groups = entries.group_by do |entry|
|
||||
# Only check for transfer-type transactions
|
||||
# Only check for transfer if it's a transaction
|
||||
next nil unless entry.entryable_type == "Transaction"
|
||||
transaction = entry.entryable
|
||||
next nil unless transaction.transfer?
|
||||
|
||||
# Create a grouping key based on transfer matching criteria
|
||||
# This groups transactions that are likely transfer pairs
|
||||
[
|
||||
entry.amount_money.abs, # Absolute amount
|
||||
entry.currency,
|
||||
entry.date
|
||||
]
|
||||
entry.entryable.transfer&.id
|
||||
end
|
||||
|
||||
# For a more intuitive UX, we do not want to show the same transfer twice in the list
|
||||
# Keep the outflow side (positive amount) and reject the inflow side (negative amount)
|
||||
deduped_entries = transfer_groups.flat_map do |group_key, grouped_entries|
|
||||
if group_key.nil? || grouped_entries.size == 1
|
||||
# Not a transfer or only one side found, keep all entries
|
||||
deduped_entries = transfer_groups.flat_map do |transfer_id, grouped_entries|
|
||||
if transfer_id.nil? || grouped_entries.size == 1
|
||||
grouped_entries
|
||||
else
|
||||
# Multiple entries with same amount/date/currency - likely a transfer pair
|
||||
# Keep the outflow side (positive amount) and reject inflow side (negative amount)
|
||||
grouped_entries.reject do |entry|
|
||||
entry.entryable_type == "Transaction" &&
|
||||
entry.entryable.transfer? &&
|
||||
entry.amount.negative? # This is the inflow side
|
||||
grouped_entries.reject do |e|
|
||||
e.entryable_type == "Transaction" &&
|
||||
e.entryable.transfer_as_inflow.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@
|
|||
<% if transaction.transfer? %>
|
||||
<%= link_to(
|
||||
entry.name,
|
||||
transaction_transfer_path(transaction),
|
||||
entry_path(entry),
|
||||
data: {
|
||||
turbo_frame: "drawer",
|
||||
turbo_prefetch: false
|
||||
|
|
|
@ -124,7 +124,6 @@ Rails.application.routes.draw do
|
|||
end
|
||||
|
||||
resources :transactions, only: %i[index new create show update destroy] do
|
||||
resource :transfer, only: :show
|
||||
resource :transfer_match, only: %i[new create]
|
||||
resource :category, only: :update, controller: :transaction_categories
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue