1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-18 20:59:39 +02:00

Separate exclude and one-time transaction handling (#2400)

* Separate exclude and one-time transaction handling

- Split transaction "exclude" and "one-time" toggles into separate controls in transaction detail view
- Updated Transaction::Search to show excluded transactions with grayed-out styling instead of filtering them out
- Modified IncomeStatement calculations to exclude both excluded and one_time transactions from totals
- Added migration to convert existing excluded transactions to also be one_time for backward compatibility
- Updated transaction list view to show asterisk for one_time transactions and gray out excluded ones
- Added controller support for kind parameter in transaction updates

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Fix linting issues

- Remove trailing whitespace from migration
- Fix ERB formatting throughout templates

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Zach Gollwitzer 2025-06-20 17:10:36 -04:00 committed by GitHub
parent c003e8c6ed
commit 63d8114b05
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 147 additions and 115 deletions

View file

@ -133,7 +133,7 @@ class TransactionsController < ApplicationController
def entry_params
entry_params = params.require(:entry).permit(
:name, :date, :amount, :currency, :excluded, :notes, :nature, :entryable_type,
entryable_attributes: [ :id, :category_id, :merchant_id, { tag_ids: [] } ]
entryable_attributes: [ :id, :category_id, :merchant_id, :kind, { tag_ids: [] } ]
)
nature = entry_params.delete(:nature)
@ -150,7 +150,7 @@ class TransactionsController < ApplicationController
cleaned_params = params.fetch(:q, {})
.permit(
:start_date, :end_date, :search, :amount,
:amount_operator, :active_accounts_only, :excluded_transactions,
:amount_operator, :active_accounts_only,
accounts: [], account_ids: [],
categories: [], merchants: [], types: [], tags: []
)

View file

@ -48,6 +48,7 @@ class IncomeStatement::CategoryStats
)
WHERE a.family_id = :family_id
AND t.kind NOT IN ('funds_movement', 'one_time', 'cc_payment')
AND ae.excluded = false
GROUP BY c.id, period, CASE WHEN ae.amount < 0 THEN 'income' ELSE 'expense' END
)
SELECT

View file

@ -44,7 +44,8 @@ class IncomeStatement::FamilyStats
er.to_currency = :target_currency
)
WHERE a.family_id = :family_id
AND t.kind NOT IN ('funds_movement', 'one_time', 'cc_payment')
AND t.kind NOT IN ('funds_movement', 'one_time', 'cc_payment')
AND ae.excluded = false
GROUP BY period, CASE WHEN ae.amount < 0 THEN 'income' ELSE 'expense' END
)
SELECT

View file

@ -45,6 +45,7 @@ class IncomeStatement::Totals
er.to_currency = :target_currency
)
WHERE at.kind NOT IN ('funds_movement', 'one_time', 'cc_payment')
AND ae.excluded = false
GROUP BY c.id, c.parent_id, CASE WHEN ae.amount < 0 THEN 'income' ELSE 'expense' END;
SQL
end

View file

@ -14,7 +14,6 @@ class Transaction::Search
attribute :merchants, array: true
attribute :tags, array: true
attribute :active_accounts_only, :boolean, default: true
attribute :excluded_transactions, :boolean, default: false
attr_reader :family
@ -29,7 +28,6 @@ class Transaction::Search
query = family.transactions
query = apply_active_accounts_filter(query, active_accounts_only)
query = apply_excluded_transactions_filter(query, excluded_transactions)
query = apply_category_filter(query, categories)
query = apply_type_filter(query, types)
query = apply_merchant_filter(query, merchants)
@ -89,13 +87,6 @@ class Transaction::Search
end
end
def apply_excluded_transactions_filter(query, excluded_transactions_filter)
unless excluded_transactions_filter
query.where(entries: { excluded: false })
else
query
end
end
def apply_category_filter(query, categories)
return query unless categories.present?

View file

@ -1,6 +1,6 @@
<%- submit_btn_css ||= 'btn btn-link' %>
<%- submit_btn_css ||= "btn btn-link" %>
<%= form_tag oauth_application_path(application), method: :delete do %>
<%= submit_tag t('doorkeeper.applications.buttons.destroy'),
<%= submit_tag t("doorkeeper.applications.buttons.destroy"),
onclick: "return confirm('#{ t('doorkeeper.applications.confirmations.destroy') }')",
class: submit_btn_css %>
<% end %>

View file

@ -1,10 +1,10 @@
<%= form_for application, url: doorkeeper_submit_path(application), as: :doorkeeper_application, html: { role: 'form' } do |f| %>
<%= form_for application, url: doorkeeper_submit_path(application), as: :doorkeeper_application, html: { role: "form" } do |f| %>
<% if application.errors.any? %>
<div class="alert alert-danger" data-alert><p><%= t('doorkeeper.applications.form.error') %></p></div>
<div class="alert alert-danger" data-alert><p><%= t("doorkeeper.applications.form.error") %></p></div>
<% end %>
<div class="form-group row">
<%= f.label :name, class: 'col-sm-2 col-form-label font-weight-bold' %>
<%= f.label :name, class: "col-sm-2 col-form-label font-weight-bold" %>
<div class="col-sm-10">
<%= f.text_field :name, class: "form-control #{ 'is-invalid' if application.errors[:name].present? }", required: true %>
<%= doorkeeper_errors_for application, :name %>
@ -12,48 +12,48 @@
</div>
<div class="form-group row">
<%= f.label :redirect_uri, class: 'col-sm-2 col-form-label font-weight-bold' %>
<%= f.label :redirect_uri, class: "col-sm-2 col-form-label font-weight-bold" %>
<div class="col-sm-10">
<%= f.text_area :redirect_uri, class: "form-control #{ 'is-invalid' if application.errors[:redirect_uri].present? }" %>
<%= doorkeeper_errors_for application, :redirect_uri %>
<span class="form-text text-secondary">
<%= t('doorkeeper.applications.help.redirect_uri') %>
<%= t("doorkeeper.applications.help.redirect_uri") %>
</span>
<% if Doorkeeper.configuration.allow_blank_redirect_uri?(application) %>
<span class="form-text text-secondary">
<%= t('doorkeeper.applications.help.blank_redirect_uri') %>
<%= t("doorkeeper.applications.help.blank_redirect_uri") %>
</span>
<% end %>
</div>
</div>
<div class="form-group row">
<%= f.label :confidential, class: 'col-sm-2 form-check-label font-weight-bold' %>
<%= f.label :confidential, class: "col-sm-2 form-check-label font-weight-bold" %>
<div class="col-sm-10">
<%= f.check_box :confidential, class: "checkbox #{ 'is-invalid' if application.errors[:confidential].present? }" %>
<%= doorkeeper_errors_for application, :confidential %>
<span class="form-text text-secondary">
<%= t('doorkeeper.applications.help.confidential') %>
<%= t("doorkeeper.applications.help.confidential") %>
</span>
</div>
</div>
<div class="form-group row">
<%= f.label :scopes, class: 'col-sm-2 col-form-label font-weight-bold' %>
<%= f.label :scopes, class: "col-sm-2 col-form-label font-weight-bold" %>
<div class="col-sm-10">
<%= f.text_field :scopes, class: "form-control #{ 'has-error' if application.errors[:scopes].present? }" %>
<%= doorkeeper_errors_for application, :scopes %>
<span class="form-text text-secondary">
<%= t('doorkeeper.applications.help.scopes') %>
<%= t("doorkeeper.applications.help.scopes") %>
</span>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<%= f.submit t('doorkeeper.applications.buttons.submit'), class: 'btn btn-primary' %>
<%= link_to t('doorkeeper.applications.buttons.cancel'), oauth_applications_path, class: 'btn btn-secondary' %>
<%= f.submit t("doorkeeper.applications.buttons.submit"), class: "btn btn-primary" %>
<%= link_to t("doorkeeper.applications.buttons.cancel"), oauth_applications_path, class: "btn btn-secondary" %>
</div>
</div>
<% end %>

View file

@ -1,5 +1,5 @@
<div class="border-bottom mb-4">
<h1><%= t('.title') %></h1>
<h1><%= t(".title") %></h1>
</div>
<%= render 'form', application: @application %>
<%= render "form", application: @application %>

View file

@ -1,16 +1,16 @@
<div class="border-bottom mb-4">
<h1><%= t('.title') %></h1>
<h1><%= t(".title") %></h1>
</div>
<p><%= link_to t('.new'), new_oauth_application_path, class: 'btn btn-success' %></p>
<p><%= link_to t(".new"), new_oauth_application_path, class: "btn btn-success" %></p>
<table class="table table-striped">
<thead>
<tr>
<th><%= t('.name') %></th>
<th><%= t('.callback_url') %></th>
<th><%= t('.confidential') %></th>
<th><%= t('.actions') %></th>
<th><%= t(".name") %></th>
<th><%= t(".callback_url") %></th>
<th><%= t(".confidential") %></th>
<th><%= t(".actions") %></th>
<th></th>
</tr>
</thead>
@ -24,13 +24,13 @@
<%= simple_format(application.redirect_uri) %>
</td>
<td class="align-middle">
<%= application.confidential? ? t('doorkeeper.applications.index.confidentiality.yes') : t('doorkeeper.applications.index.confidentiality.no') %>
<%= application.confidential? ? t("doorkeeper.applications.index.confidentiality.yes") : t("doorkeeper.applications.index.confidentiality.no") %>
</td>
<td class="align-middle">
<%= link_to t('doorkeeper.applications.buttons.edit'), edit_oauth_application_path(application), class: 'btn btn-link' %>
<%= link_to t("doorkeeper.applications.buttons.edit"), edit_oauth_application_path(application), class: "btn btn-link" %>
</td>
<td class="align-middle">
<%= render 'delete_form', application: application %>
<%= render "delete_form", application: application %>
</td>
</tr>
<% end %>

View file

@ -1,5 +1,5 @@
<div class="border-bottom mb-4">
<h1><%= t('.title') %></h1>
<h1><%= t(".title") %></h1>
</div>
<%= render 'form', application: @application %>
<%= render "form", application: @application %>

View file

@ -1,39 +1,39 @@
<div class="border-bottom mb-4">
<h1><%= t('.title', name: @application.name) %></h1>
<h1><%= t(".title", name: @application.name) %></h1>
</div>
<div class="row">
<div class="col-md-8">
<h4><%= t('.application_id') %>:</h4>
<h4><%= t(".application_id") %>:</h4>
<p><code class="bg-light" id="application_id"><%= @application.uid %></code></p>
<h4><%= t('.secret') %>:</h4>
<h4><%= t(".secret") %>:</h4>
<p>
<code class="bg-light" id="secret">
<% secret = flash[:application_secret].presence || @application.plaintext_secret %>
<% if secret.blank? && Doorkeeper.config.application_secret_hashed? %>
<span class="bg-light font-italic text-uppercase text-muted"><%= t('.secret_hashed') %></span>
<span class="bg-light font-italic text-uppercase text-muted"><%= t(".secret_hashed") %></span>
<% else %>
<%= secret %>
<% end %>
</code>
</p>
<h4><%= t('.scopes') %>:</h4>
<h4><%= t(".scopes") %>:</h4>
<p>
<code class="bg-light" id="scopes">
<% if @application.scopes.present? %>
<%= @application.scopes %>
<% else %>
<span class="bg-light font-italic text-uppercase text-muted"><%= t('.not_defined') %></span>
<span class="bg-light font-italic text-uppercase text-muted"><%= t(".not_defined") %></span>
<% end %>
</code>
</p>
<h4><%= t('.confidential') %>:</h4>
<h4><%= t(".confidential") %>:</h4>
<p><code class="bg-light" id="confidential"><%= @application.confidential? %></code></p>
<h4><%= t('.callback_urls') %>:</h4>
<h4><%= t(".callback_urls") %>:</h4>
<% if @application.redirect_uri.present? %>
<table>
@ -43,21 +43,21 @@
<code class="bg-light"><%= uri %></code>
</td>
<td>
<%= link_to t('doorkeeper.applications.buttons.authorize'), oauth_authorization_path(client_id: @application.uid, redirect_uri: uri, response_type: 'code', scope: @application.scopes), class: 'btn btn-success', target: '_blank' %>
<%= link_to t("doorkeeper.applications.buttons.authorize"), oauth_authorization_path(client_id: @application.uid, redirect_uri: uri, response_type: "code", scope: @application.scopes), class: "btn btn-success", target: "_blank" %>
</td>
</tr>
<% end %>
</table>
<% else %>
<span class="bg-light font-italic text-uppercase text-muted"><%= t('.not_defined') %></span>
<span class="bg-light font-italic text-uppercase text-muted"><%= t(".not_defined") %></span>
<% end %>
</div>
<div class="col-md-4">
<h3><%= t('.actions') %></h3>
<h3><%= t(".actions") %></h3>
<p><%= link_to t('doorkeeper.applications.buttons.edit'), edit_oauth_application_path(@application), class: 'btn btn-primary' %></p>
<p><%= link_to t("doorkeeper.applications.buttons.edit"), edit_oauth_application_path(@application), class: "btn btn-primary" %></p>
<p><%= render 'delete_form', application: @application, submit_btn_css: 'btn btn-danger' %></p>
<p><%= render "delete_form", application: @application, submit_btn_css: "btn btn-danger" %></p>
</div>
</div>

View file

@ -3,7 +3,7 @@
<div class="mx-auto w-12 h-12 rounded-full bg-destructive-surface flex items-center justify-center mb-4">
<%= icon("alert-circle", class: "w-6 h-6 text-destructive") %>
</div>
<h1 class="text-2xl font-medium text-primary"><%= t('doorkeeper.authorizations.error.title') %></h1>
<h1 class="text-2xl font-medium text-primary"><%= t("doorkeeper.authorizations.error.title") %></h1>
</div>
<div class="bg-surface-inset rounded-lg p-4">

View file

@ -3,12 +3,12 @@
<div class="mx-auto w-12 h-12 rounded-full bg-surface-inset flex items-center justify-center mb-4">
<%= icon("loader-circle", class: "w-6 h-6 text-primary animate-spin") %>
</div>
<h1 class="text-2xl font-medium text-primary"><%= t('.title') %></h1>
<h1 class="text-2xl font-medium text-primary"><%= t(".title") %></h1>
<p class="text-sm text-secondary">Redirecting you back to the application...</p>
</div>
</div>
<% turbo_disabled = @pre_auth.redirect_uri&.start_with?('maybeapp://') || params[:display] == 'mobile' %>
<% turbo_disabled = @pre_auth.redirect_uri&.start_with?("maybeapp://") || params[:display] == "mobile" %>
<%= form_tag @pre_auth.redirect_uri, method: :post, name: :redirect_form, authenticity_token: false, data: { turbo: !turbo_disabled } do %>
<% auth.body.compact.each do |key, value| %>
<%= hidden_field_tag key, value %>

View file

@ -5,13 +5,13 @@
<div class="bg-container rounded-xl p-6 space-y-6">
<div class="space-y-2 text-center">
<p class="text-sm text-secondary">
<%= raw t('.prompt', client_name: content_tag(:span, @pre_auth.client.name, class: 'font-medium text-primary')) %>
<%= raw t(".prompt", client_name: content_tag(:span, @pre_auth.client.name, class: "font-medium text-primary")) %>
</p>
</div>
<% if @pre_auth.scopes.count > 0 %>
<div class="bg-surface-inset rounded-lg p-4 space-y-3">
<p class="text-sm font-medium text-primary"><%= t('.able_to') %>:</p>
<p class="text-sm font-medium text-primary"><%= t(".able_to") %>:</p>
<ul class="space-y-2">
<% @pre_auth.scopes.each do |scope| %>
<li class="flex items-start gap-2 text-sm text-secondary">
@ -24,7 +24,7 @@
<% end %>
<div class="space-y-3">
<% turbo_disabled = params[:redirect_uri]&.start_with?('maybeapp://') || params[:display] == 'mobile' %>
<% turbo_disabled = params[:redirect_uri]&.start_with?("maybeapp://") || params[:display] == "mobile" %>
<%= form_tag oauth_authorization_path, method: :post, class: "w-full", data: { turbo: !turbo_disabled } do %>
<%= hidden_field_tag :client_id, @pre_auth.client.uid, id: nil %>
<%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri, id: nil %>
@ -38,7 +38,7 @@
<%= hidden_field_tag :display, params[:display], id: nil %>
<% end %>
<%= render ButtonComponent.new(
text: t('doorkeeper.authorizations.buttons.authorize'),
text: t("doorkeeper.authorizations.buttons.authorize"),
variant: :primary,
size: :lg,
full_width: true,
@ -46,7 +46,7 @@
data: { disable_with: "Authorizing..." }
) %>
<% end %>
<%= form_tag oauth_authorization_path, method: :delete, class: "w-full", data: { turbo: !turbo_disabled } do %>
<%= hidden_field_tag :client_id, @pre_auth.client.uid, id: nil %>
<%= hidden_field_tag :redirect_uri, @pre_auth.redirect_uri, id: nil %>
@ -60,7 +60,7 @@
<%= hidden_field_tag :display, params[:display], id: nil %>
<% end %>
<%= render ButtonComponent.new(
text: t('doorkeeper.authorizations.buttons.deny'),
text: t("doorkeeper.authorizations.buttons.deny"),
variant: :outline,
size: :lg,
full_width: true,

View file

@ -3,7 +3,7 @@
<div class="mx-auto w-12 h-12 rounded-full bg-success-surface flex items-center justify-center mb-4">
<%= icon("check", class: "w-6 h-6 text-success") %>
</div>
<h1 class="text-2xl font-medium text-primary"><%= t('.title') %></h1>
<h1 class="text-2xl font-medium text-primary"><%= t(".title") %></h1>
</div>
<div class="bg-surface-inset rounded-lg p-4">

View file

@ -1,4 +1,4 @@
<%- submit_btn_css ||= 'btn btn-link' %>
<%- submit_btn_css ||= "btn btn-link" %>
<%= form_tag oauth_authorized_application_path(application), method: :delete do %>
<%= submit_tag t('doorkeeper.authorized_applications.buttons.revoke'), onclick: "return confirm('#{ t('doorkeeper.authorized_applications.confirmations.revoke') }')", class: submit_btn_css %>
<%= submit_tag t("doorkeeper.authorized_applications.buttons.revoke"), onclick: "return confirm('#{ t('doorkeeper.authorized_applications.confirmations.revoke') }')", class: submit_btn_css %>
<% end %>

View file

@ -1,13 +1,13 @@
<header class="page-header">
<h1><%= t('doorkeeper.authorized_applications.index.title') %></h1>
<h1><%= t("doorkeeper.authorized_applications.index.title") %></h1>
</header>
<main role="main">
<table class="table table-striped">
<thead>
<tr>
<th><%= t('doorkeeper.authorized_applications.index.application') %></th>
<th><%= t('doorkeeper.authorized_applications.index.created_at') %></th>
<th><%= t("doorkeeper.authorized_applications.index.application") %></th>
<th><%= t("doorkeeper.authorized_applications.index.created_at") %></th>
<th></th>
</tr>
</thead>
@ -15,8 +15,8 @@
<% @applications.each do |application| %>
<tr>
<td><%= application.name %></td>
<td><%= application.created_at.strftime(t('doorkeeper.authorized_applications.index.date_format')) %></td>
<td><%= render 'delete_form', application: application %></td>
<td><%= application.created_at.strftime(t("doorkeeper.authorized_applications.index.date_format")) %></td>
<td><%= render "delete_form", application: application %></td>
</tr>
<% end %>
</tbody>

View file

@ -4,22 +4,22 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><%= t('doorkeeper.layouts.admin.title') %></title>
<title><%= t("doorkeeper.layouts.admin.title") %></title>
<%= stylesheet_link_tag "doorkeeper/admin/application" %>
<%= csrf_meta_tags %>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark mb-5">
<%= link_to t('doorkeeper.layouts.admin.nav.oauth2_provider'), oauth_applications_path, class: 'navbar-brand' %>
<%= link_to t("doorkeeper.layouts.admin.nav.oauth2_provider"), oauth_applications_path, class: "navbar-brand" %>
<div class="collapse navbar-collapse">
<ul class="navbar-nav mr-auto">
<li class="nav-item <%= 'active' if request.path == oauth_applications_path %>">
<%= link_to t('doorkeeper.layouts.admin.nav.applications'), oauth_applications_path, class: 'nav-link' %>
<li class="nav-item <%= "active" if request.path == oauth_applications_path %>">
<%= link_to t("doorkeeper.layouts.admin.nav.applications"), oauth_applications_path, class: "nav-link" %>
</li>
<% if respond_to?(:root_path) %>
<li class="nav-item">
<%= link_to t('doorkeeper.layouts.admin.nav.home'), root_path, class: 'nav-link' %>
<%= link_to t("doorkeeper.layouts.admin.nav.home"), root_path, class: "nav-link" %>
</li>
<% end %>
</ul>

View file

@ -91,4 +91,4 @@
) %>
</div>
</div>
<% end %>
<% end %>

View file

@ -99,4 +99,4 @@
<% end %>
</div>
</div>
<% end %>
<% end %>

View file

@ -57,4 +57,4 @@
) %>
</div>
<% end %>
<% end %>
<% end %>

View file

@ -189,4 +189,4 @@
</div>
</div>
<% end %>
<% end %>
<% end %>

View file

@ -6,9 +6,10 @@
<%= turbo_frame_tag dom_id(transaction) do %>
<div class="grid grid-cols-12 items-center text-primary text-sm font-medium p-4 lg:p-4
<%= @focused_record == entry || @focused_record == transaction ?
"border border-gray-900 rounded-lg" : "" %>">
"border border-gray-900 rounded-lg" : "" %>
<%= entry.excluded ? "opacity-50 text-gray-400" : "" %>">
<div class="pr-4 lg:pr-10 flex items-center gap-3 lg:gap-4 col-span-8 <%= view_ctx == 'global' ? 'lg:col-span-8' : 'lg:col-span-6' %>">
<div class="pr-4 lg:pr-10 flex items-center gap-3 lg:gap-4 col-span-8 <%= view_ctx == "global" ? "lg:col-span-8" : "lg:col-span-6" %>">
<%= check_box_tag dom_id(entry, "selection"),
disabled: transaction.transfer.present?,
class: "checkbox checkbox--light",
@ -61,7 +62,7 @@
</div>
<div class="flex items-center gap-1 flex-shrink-0">
<% if entry.excluded %>
<% if transaction.one_time? %>
<span class="text-orange-500" title="One-time <%= entry.amount.negative? ? "income" : "expense" %> (excluded from averages)">
<%= icon "asterisk", size: "sm", color: "current" %>
</span>

View file

@ -106,13 +106,34 @@
data: { controller: "auto-submit-form" } do |f| %>
<div class="flex cursor-pointer items-center gap-4 justify-between">
<div class="text-sm space-y-1">
<h4 class="text-primary">One-time <%= @entry.amount.negative? ? "Income" : "Expense" %></h4>
<p class="text-secondary">One-time transactions will be excluded from certain budgeting calculations and reports to help you see what's really important.</p>
<h4 class="text-primary">Exclude</h4>
<p class="text-secondary">Excluded transactions will be removed from budgeting calculations and reports.</p>
</div>
<%= f.toggle :excluded, { data: { auto_submit_form_target: "auto" } } %>
</div>
<% end %>
</div>
<div class="pb-4">
<%= styled_form_with model: @entry,
url: transaction_path(@entry),
class: "p-3",
data: { controller: "auto-submit-form" } do |f| %>
<%= f.fields_for :entryable do |ef| %>
<div class="flex cursor-pointer items-center gap-4 justify-between">
<div class="text-sm space-y-1">
<h4 class="text-primary">One-time <%= @entry.amount.negative? ? "Income" : "Expense" %></h4>
<p class="text-secondary">One-time transactions will be excluded from certain budgeting calculations and reports to help you see what's really important.</p>
</div>
<%= ef.toggle :kind, {
checked: @entry.transaction.one_time?,
data: { auto_submit_form_target: "auto" }
}, "one_time", "standard" %>
</div>
<% end %>
<% end %>
<div class="flex items-center justify-between gap-4 p-3">
<div class="text-sm space-y-1">

View file

@ -0,0 +1,33 @@
class UpdateExcludedTransactionsToOneTime < ActiveRecord::Migration[7.2]
def change
reversible do |dir|
dir.up do
# Update all transactions that have excluded entries to be one_time
# They remain excluded as well since users were using excluded as "one time" before
execute <<~SQL
UPDATE transactions
SET kind = 'one_time'
FROM entries
WHERE entries.entryable_id = transactions.id
AND entries.entryable_type = 'Transaction'
AND entries.excluded = true
AND transactions.kind = 'standard'
SQL
end
dir.down do
# Revert one_time transactions back to standard if their entry is excluded
# This assumes these were the ones we migrated in the up method
execute <<~SQL
UPDATE transactions
SET kind = 'standard'
FROM entries
WHERE entries.entryable_id = transactions.id
AND entries.entryable_type = 'Transaction'
AND entries.excluded = true
AND transactions.kind = 'one_time'
SQL
end
end
end
end

2
db/schema.rb generated
View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2025_06_18_120703) do
ActiveRecord::Schema[7.2].define(version: 2025_06_20_204550) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"

View file

@ -204,6 +204,20 @@ class IncomeStatementTest < ActiveSupport::TestCase
assert_equal Money.new(900, @family.currency), totals.expense_money
end
test "excludes excluded transactions from income statement calculations" do
# Create an excluded transaction
excluded_transaction_entry = create_transaction(account: @checking_account, amount: 250, category: @groceries_category)
excluded_transaction_entry.update!(excluded: true)
income_statement = IncomeStatement.new(@family)
totals = income_statement.totals
# Should exclude excluded transactions
assert_equal 4, totals.transactions_count # Only original 4 transactions
assert_equal Money.new(1000, @family.currency), totals.income_money
assert_equal Money.new(900, @family.currency), totals.expense_money
end
# NEW TESTS: Interval-Based Calculations
test "different intervals return different statistical results with multi-period data" do
# Clear existing transactions

View file

@ -298,35 +298,4 @@ class Transaction::SearchTest < ActiveSupport::TestCase
assert_equal Money.new(0, "USD"), totals.expense_money
assert_equal Money.new(0, "USD"), totals.income_money
end
test "totals respects excluded transactions filter from search" do
# Create an excluded transaction (should be excluded by default)
excluded_entry = create_transaction(
account: @checking_account,
amount: 100,
kind: "standard"
)
excluded_entry.update!(excluded: true) # Marks it as excluded
# Create a normal transaction
normal_entry = create_transaction(
account: @checking_account,
amount: 50,
kind: "standard"
)
# Default behavior should exclude excluded transactions
search = Transaction::Search.new(@family)
totals = search.totals
assert_equal 1, totals.count
assert_equal Money.new(50, "USD"), totals.expense_money # Only non-excluded transaction
# Explicitly include excluded transactions
search_with_excluded = Transaction::Search.new(@family, filters: { excluded_transactions: true })
totals_with_excluded = search_with_excluded.totals
assert_equal 2, totals_with_excluded.count
assert_equal Money.new(150, "USD"), totals_with_excluded.expense_money # Both transactions
end
end