The personal finance app for everyone (by everyone)
Ruby
Add a Once frequency for a single bill or income (#4975)
Taaqif Peck (Tye)eaca5de62496
diff --git a/app/controllers/recurring_transactions/smart_fills_controller.rb b/app/controllers/recurring_transactions/smart_fills_controller.rbindex 9a60474515..721651fa88 100644--- a/app/controllers/recurring_transactions/smart_fills_controller.rb+++ b/app/controllers/recurring_transactions/smart_fills_controller.rb@@ -70,7 +70,9 @@ class RecurringTransactions::SmartFillsController < RecurringTransactionsControl# in here and is dropped. The suggested category is dropped too: the form# keeps the transaction's own category from the prefill.# The due date follows the cadence's own anchor: weekday for weekly-style- # presets, month for annual, day-of-month for the monthly-style rest.+ # presets, month for annual, day-of-month for the monthly-style rest. A+ # one-off keeps the charge it was read from: the prefill's next monthly+ # date is a guess that only a repeating bill needs.def apply_suggestion(suggestion)@recurring_transaction.name = suggestion.name if suggestion.name.present?@recurring_transaction.amount = suggestion.amount if suggestion.amount.present?@@ -78,7 +80,9 @@ class RecurringTransactions::SmartFillsController < RecurringTransactionsControl@recurring_transaction.autopay = suggestion.autopay unless suggestion.autopay.nil?today = Date.current- if %w[weekly biweekly].include?(suggestion.frequency) && suggestion.weekday.present?+ if suggestion.frequency == RecurringTransaction::FrequencyPreset::ONCE+ @recurring_transaction.first_due_on = @source_entry.date+ elsif %w[weekly biweekly].include?(suggestion.frequency) && suggestion.weekday.present?@recurring_transaction.first_due_on = today + ((suggestion.weekday - today.wday) % 7)elsif suggestion.frequency == "annual" && suggestion.month_of_year.present?@recurring_transaction.first_due_on = next_annual_occurrence(diff --git a/app/controllers/recurring_transactions_controller.rb b/app/controllers/recurring_transactions_controller.rbindex cc01ac0e68..4ec2fead7e 100644--- a/app/controllers/recurring_transactions_controller.rb+++ b/app/controllers/recurring_transactions_controller.rb@@ -396,7 +396,8 @@ class RecurringTransactionsController < ApplicationController:payment_url, :autopay, :notes, :bill_type, :category_id,:renews_on, :trial_ends_on, :cancelled_on, :end_after_count,:frequency_preset, :frequency_day_of_month, :frequency_second_day_of_month,- :frequency_weekday, :frequency_month_of_year, :frequency_interval, :frequency_interval_unit+ :frequency_weekday, :frequency_month_of_year, :frequency_interval, :frequency_interval_unit,+ :frequency_once_on)end@@ -432,6 +433,9 @@ class RecurringTransactionsController < ApplicationController@recurring_transaction.frequency_month_of_year = detection.month_of_year@recurring_transaction.frequency_interval = detection.interval@recurring_transaction.frequency_interval_unit = detection.interval_unit+ # Switching to Once starts from the date the bill is next due, not its+ # first due date, which is long past for an older bill.+ @recurring_transaction.frequency_once_on = detection.once_on || @recurring_transaction.next_due_dateend# A bill outliving its own price is the normal case, and the only way to@@ -491,7 +495,8 @@ class RecurringTransactionsController < ApplicationControllerweekday: @recurring_transaction.frequency_weekday,month_of_year: @recurring_transaction.frequency_month_of_year,interval: @recurring_transaction.frequency_interval,- interval_unit: @recurring_transaction.frequency_interval_unit+ interval_unit: @recurring_transaction.frequency_interval_unit,+ once_on: @recurring_transaction.frequency_once_on)# A hand-set cadence is intent, not a guess for detection to correct.diff --git a/app/models/assistant/function/create_bill.rb b/app/models/assistant/function/create_bill.rbindex 12c8371625..47dc43063b 100644--- a/app/models/assistant/function/create_bill.rb+++ b/app/models/assistant/function/create_bill.rb@@ -17,7 +17,8 @@ class Assistant::Function::CreateBill < Assistant::Functioncreate the bill without an account.- category_name must exactly match a name returned by get_categories.- first_due_on seeds the schedule: its day of month (or weekday for weekly- cadences) becomes the recurring due day.+ cadences) becomes the recurring due day. frequency "once" is a single+ occurrence on first_due_on and does not repeat.- Transfers between accounts cannot be created here.Confirm the details with the user before calling this.diff --git a/app/models/assistant/function/update_bill.rb b/app/models/assistant/function/update_bill.rbindex 26a2c8892a..81b2b9400a 100644--- a/app/models/assistant/function/update_bill.rb+++ b/app/models/assistant/function/update_bill.rb@@ -49,7 +49,7 @@ class Assistant::Function::UpdateBill < Assistant::Functionfrequency: {type: "string",enum: RecurringTransaction::FrequencyPreset::PRESETS,- description: "New cadence. Combine with due_day_of_month / weekday / month_of_year as the cadence needs."+ description: "New cadence. once is a single occurrence on the bill's current due date. Combine other cadences with due_day_of_month / weekday / month_of_year as needed."},due_day_of_month: { type: "integer", minimum: 1, maximum: 31 },weekday: { type: "integer", minimum: 0, maximum: 6, description: "0 = Sunday." },@@ -265,6 +265,15 @@ class Assistant::Function::UpdateBill < Assistant::Functionmonth_of_year: params["month_of_year"])+ # A refused cadence (a paid one-off's date, say) is reported, not saved+ # around: the save below would clear the error and drop the change.+ if series.errors.any?+ return {+ error: series.errors.full_messages.to_sentence,+ hint: "Fix the named fields and retry once."+ }+ end+if appliedseries.pin_schedulechanged << "schedule"diff --git a/app/models/provider/anthropic/bill_setup_suggester.rb b/app/models/provider/anthropic/bill_setup_suggester.rbindex 97435533ef..628c33c270 100644--- a/app/models/provider/anthropic/bill_setup_suggester.rb+++ b/app/models/provider/anthropic/bill_setup_suggester.rb@@ -101,6 +101,7 @@ class Provider::Anthropic::BillSetupSuggesterRules:- Infer the cadence from the gaps between the dates, never from the row count.+ Use "once" only for a single charge with no repeating gap.- amount is the typical recent charge as a positive number; when amounts drift,prefer the most recent ones.- day_of_month is the modal charge day (monthly-style cadences only); weekdaydiff --git a/app/models/provider/openai/bill_setup_suggester.rb b/app/models/provider/openai/bill_setup_suggester.rbindex 8d9ff5f9cc..663dfa15c0 100644--- a/app/models/provider/openai/bill_setup_suggester.rb+++ b/app/models/provider/openai/bill_setup_suggester.rb@@ -65,7 +65,8 @@ class Provider::Openai::BillSetupSuggesterRules:- Infer the cadence from the gaps between the dates, never from the row count.- frequency is one of: monthly, weekly, biweekly, semimonthly, quarterly, semiannual, annual.+ frequency is one of: once, monthly, weekly, biweekly, semimonthly, quarterly, semiannual, annual.+ Use "once" only for a single charge with no repeating gap.- amount is the typical recent charge as a positive number; when amounts drift,prefer the most recent ones.- day_of_month is the modal charge day (monthly-style cadences only); weekdaydiff --git a/app/models/recurring_transaction.rb b/app/models/recurring_transaction.rbindex d1af8653c1..f4c713ea4b 100644--- a/app/models/recurring_transaction.rb+++ b/app/models/recurring_transaction.rb@@ -87,7 +87,7 @@ class RecurringTransaction < ApplicationRecord# FrequencyPreset and the controller translate these on save. Not persisted.attr_accessor :frequency_preset, :frequency_day_of_month, :frequency_second_day_of_month,:frequency_weekday, :frequency_month_of_year, :frequency_interval, :frequency_interval_unit,- :first_due_on, :is_income+ :frequency_once_on, :first_due_on, :is_income# A scheme, followed by either "//" or by something that is not a port number.# "example.com:8080" is a host and port, not a scheme, so it does not match.@@ -441,7 +441,15 @@ class RecurringTransaction < ApplicationRecord# a $120 annual bill contributes $10, a $10 weekly bill about $43.45. This# is the honest number for "recurring commitment" style totals; summing raw# amounts across mixed cadences answers no meaningful question.+ # A one-off is a single payment, not a rate, so it adds nothing to+ # "per month" commitment totals. The occurrence still shows on its date.+ def one_off?+ RecurringTransaction::FrequencyPreset.detect(self).key == RecurringTransaction::FrequencyPreset::ONCE+ end+def monthly_equivalent_amount+ return amount_money * 0 if one_off?+amount_money * (schedule.occurrences_per_year / 12.0)enddiff --git a/app/models/recurring_transaction/declared_bill.rb b/app/models/recurring_transaction/declared_bill.rbindex 379b448fba..6b5f1bc292 100644--- a/app/models/recurring_transaction/declared_bill.rb+++ b/app/models/recurring_transaction/declared_bill.rb@@ -103,7 +103,8 @@ class RecurringTransactionweekday: due.wday,month_of_year: due.month,interval: attrs[:frequency_interval],- interval_unit: attrs[:frequency_interval_unit]+ interval_unit: attrs[:frequency_interval_unit],+ once_on: due)recurringdiff --git a/app/models/recurring_transaction/frequency_preset.rb b/app/models/recurring_transaction/frequency_preset.rbindex bdb6530f64..996bc43b57 100644--- a/app/models/recurring_transaction/frequency_preset.rb+++ b/app/models/recurring_transaction/frequency_preset.rb@@ -4,7 +4,12 @@ class RecurringTransaction# interval 2); anything the picker cannot express reads back as CUSTOM and# is left untouched.class FrequencyPreset- PRESETS = %w[monthly weekly biweekly semimonthly quarterly semiannual annual].freeze+ # "once" is one occurrence on a date. It is stored as a yearly rule capped+ # at a single payment, so the schedule engine can place it without a new+ # frequency value. Listed with the named presets so the picker and the+ # assistant offer the same set.+ ONCE = "once"+ PRESETS = %w[once monthly weekly biweekly semimonthly quarterly semiannual annual].freezeCUSTOM = "custom"# "Every N weeks, months or years": one rule of any interval, for the@@ -15,7 +20,7 @@ class RecurringTransactionMAX_INTERVAL = 99Detection = Data.define(:key, :day_of_month, :second_day_of_month, :weekday, :month_of_year,- :interval, :interval_unit)+ :interval, :interval_unit, :once_on)class << self# Reads the series' rules back into picker values. Zero rules is the@@ -23,6 +28,12 @@ class RecurringTransactiondef detect(recurring)rules = live_rules(recurring)+ if once_schedule?(recurring, rules)+ rule = rules.first+ return detection(key: ONCE, once_on: recurring.anchor_date || recurring.next_expected_date,+ day_of_month: rule.day_of_month, month_of_year: rule.month_of_year)+ end+casewhen rules.empty?detection(key: "monthly", day_of_month: recurring.expected_day_of_month)@@ -50,7 +61,7 @@ class RecurringTransaction# An out-of-range interval or unknown unit is reported on the record and# rewrites nothing; callers check errors before saving.def apply(recurring, preset:, day_of_month: nil, second_day_of_month: nil, weekday: nil, month_of_year: nil,- interval: nil, interval_unit: nil)+ interval: nil, interval_unit: nil, once_on: nil)return false if preset.blank? || preset == CUSTOMreturn false unless PRESETS.include?(preset) || preset == INTERVAL@@ -60,6 +71,28 @@ class RecurringTransactionreturn falseend+ was_once = once_schedule?(recurring)+ once_date = nil+ if preset == ONCE+ # The caller may already have changed bill type or the end cap in+ # memory. The lock has to see the schedule that is saved, or marking+ # a paid one-off as an installment would let its date move.+ was_once = persisted_once_schedule?(recurring)+ once_date = resolve_once_date(recurring, once_on, was_once)+ if once_date.nil?+ recurring.errors.add(:base, I18n.t("recurring_transactions.create.due_date_required"))+ return false+ end++ # A paid one-off is that payment. Moving the date would keep the+ # paid row and generate a second, open one, so the change is refused.+ locked_on = was_once ? persisted_once_date(recurring) : current_once_date(recurring)+ if was_once && once_date != locked_on && settled_occurrence?(recurring, locked_on)+ recurring.errors.add(:base, I18n.t("recurring_transactions.update.once_date_locked"))+ return false+ end+ end+reference = recurring.anchor_date || recurring.last_occurrence_date || Date.currenttarget = target_detection(recurring, reference, preset,day_of_month: presence_int(day_of_month),@@ -67,10 +100,15 @@ class RecurringTransactionweekday: presence_int(weekday),month_of_year: presence_int(month_of_year),interval: interval,- interval_unit: interval_unit)+ interval_unit: interval_unit,+ once_on: once_date)return false if target == detect(recurring)write(recurring, target, reference)+ # Leaving "once" must drop the one-payment cap, or the next cadence+ # would also end after a single occurrence. An installment owns that+ # cap itself, so its count stays.+ release_once_end(recurring) if was_once && preset != ONCE && !recurring.typed_installment?trueend@@ -95,6 +133,12 @@ class RecurringTransactionwhen "annual"I18n.t("recurring_transactions.frequency.annual",month: I18n.t("date.month_names")[found.month_of_year], day: day_phrase(found.day_of_month))+ when ONCE+ if found.once_on+ I18n.t("recurring_transactions.frequency.once_on", date: I18n.l(found.once_on, format: :long))+ else+ I18n.t("recurring_transactions.frequency.once")+ endwhen INTERVALinterval_label(found)else@@ -104,8 +148,83 @@ class RecurringTransactionprivatedef detection(key:, day_of_month: nil, second_day_of_month: nil, weekday: nil, month_of_year: nil,- interval: nil, interval_unit: nil)- Detection.new(key:, day_of_month:, second_day_of_month:, weekday:, month_of_year:, interval:, interval_unit:)+ interval: nil, interval_unit: nil, once_on: nil)+ Detection.new(key:, day_of_month:, second_day_of_month:, weekday:, month_of_year:, interval:, interval_unit:,+ once_on:)+ end++ # A one-payment yearly rule that is not an installment. Installments+ # carry their own count, so a one-payment plan stays an installment.+ def once_schedule?(recurring, rules = live_rules(recurring))+ return false if recurring.typed_installment?+ return false unless recurring.end_mode == "after_count" && recurring.end_after_count == 1+ return false unless rules.size == 1++ rule = rules.first+ rule.frequency == "yearly" && rule.interval == 1 && rule.day_of_month.present? && rule.weekday.blank?+ end++ def current_once_date(recurring)+ recurring.anchor_date || recurring.next_expected_date+ end++ # The once date as stored, ignoring an anchor the caller has already+ # reassigned. next_expected_date is never null.+ def persisted_once_date(recurring)+ recurring.attribute_in_database("anchor_date") || recurring.attribute_in_database("next_expected_date")+ end++ # once_schedule? read against the saved row. Rules built in memory+ # during this edit are not part of it; a rule marked for destruction+ # still is, until the save.+ def persisted_once_schedule?(recurring)+ return false unless recurring.persisted?+ return false if recurring.attribute_in_database("bill_type") == "installment"+ return false unless recurring.attribute_in_database("end_mode") == "after_count" &&+ recurring.attribute_in_database("end_after_count") == 1++ rules = recurring.recurrence_rules.reject(&:new_record?)+ return false unless rules.size == 1++ rule = rules.first+ rule.frequency == "yearly" && rule.interval == 1 && rule.day_of_month.present? && rule.weekday.blank?+ end++ # Whether the occurrence on `date` is closed or carries an allocation,+ # a payment the generator will not delete. Only that date: rows left by+ # an earlier repeating schedule say nothing about the one-off.+ def settled_occurrence?(recurring, date)+ occurrences = recurring.recurring_occurrences.where(original_due_on: date)+ occurrences.closed.exists? ||+ RecurringAllocation.where(recurring_occurrence_id: occurrences.select(:id)).exists?+ end++ # A blank date keeps an existing one-off where it is. Anything else+ # becomes due on what the bill currently shows as its due date: the+ # anchor is its first due date and stays put as occurrences advance, so+ # it can be months behind. A date that was typed but cannot be parsed+ # is refused, rather than quietly kept.+ def resolve_once_date(recurring, once_on, was_once)+ return nil if once_on.present? && strict_date(once_on).nil?++ strict_date(once_on) ||+ (current_once_date(recurring) if was_once || !recurring.persisted?) ||+ recurring.next_due_date+ end++ def strict_date(value)+ return value if value.is_a?(Date)+ return nil if value.blank?++ Date.iso8601(value.to_s)+ rescue Date::Error+ nil+ end++ def release_once_end(recurring)+ recurring.end_mode = "never"+ recurring.end_after_count = nil+ recurring.end_on = nilend# Monthly and yearly rules anchored on an nth weekday ("3rd Friday")@@ -147,8 +266,10 @@ class RecurringTransaction# The Detection the submitted form values resolve to, with the same# defaulting write() will use, so equality against detect() is exact.def target_detection(recurring, reference, preset, day_of_month:, second_day_of_month:, weekday:, month_of_year:,- interval:, interval_unit:)+ interval:, interval_unit:, once_on:)case preset+ when ONCE+ detection(key: ONCE, once_on: once_on, day_of_month: once_on.day, month_of_year: once_on.month)when "monthly", "quarterly", "semiannual"detection(key: preset, day_of_month: day_of_month || recurring.expected_day_of_month)when "weekly", "biweekly"@@ -195,6 +316,16 @@ class RecurringTransactionwhen "annual"build_rule(recurring, frequency: "yearly", day_of_month: target.day_of_month,month_of_year: target.month_of_year)+ when ONCE+ # The anchor is the only due date. next_expected_date is the hint+ # the bills list reads, so it has to move with that date.+ recurring.anchor_date = target.once_on+ recurring.next_expected_date = target.once_on+ recurring.end_mode = "after_count"+ recurring.end_after_count = 1+ recurring.end_on = nil+ build_rule(recurring, frequency: "yearly", day_of_month: target.day_of_month,+ month_of_year: target.month_of_year)when INTERVALrecurring.anchor_date ||= referencebuild_rule(recurring, frequency: target.interval_unit, interval: target.interval,@@ -225,7 +356,7 @@ class RecurringTransaction# cadences; other cadences populate it but do not schedule from it.def authoritative_day(target, reference)day_anchored = case target.key- when "monthly", "semimonthly", "quarterly", "semiannual", "annual" then true+ when "monthly", "semimonthly", "quarterly", "semiannual", "annual", ONCE then truewhen INTERVAL then target.interval_unit != "weekly"else falseenddiff --git a/app/models/recurring_transaction/occurrence_generator.rb b/app/models/recurring_transaction/occurrence_generator.rbindex e4551d7df3..41ad600f13 100644--- a/app/models/recurring_transaction/occurrence_generator.rb+++ b/app/models/recurring_transaction/occurrence_generator.rb@@ -3,8 +3,9 @@ class RecurringTransaction# upsert keyed on (series, original_due_on), so re-running only adds missing# rows and never duplicates or touches existing ones.#- # Only scheduled, allocation-free, not-yet-due rows are ever deleted. Anything- # closed or carrying a payment is immutable history.+ # Only scheduled, allocation-free rows are ever deleted, and only ones that+ # are not yet due — except the date a one-payment plan was moved off.+ # Anything closed or carrying a payment is immutable history.class OccurrenceGeneratorHORIZON_DAYS = 90@@ -28,6 +29,12 @@ class RecurringTransaction# cycle start, since their history predates the row.from = [ from, series.anchor_date ].compact.max if series.manual?+ # A one-payment plan's only date can already be past. The clamp above+ # refuses to look behind today, which would drop that only occurrence.+ if single_payment? && series.anchor_date+ from = [ from, series.anchor_date ].min+ end+through ||= default_horizon(schedule)upsert_window(from, through)@@ -36,11 +43,13 @@ class RecurringTransaction# After a schedule edit: drop the re-generatable future and rebuild it under# the new rules. Rows with payments or closed state are kept as they were.def regenerate_future!(through: nil)- series.recurring_occurrences- .open_status- .where("due_on >= ?", Date.current)- .where.not(id: RecurringAllocation.select(:recurring_occurrence_id))- .delete_all+ removable = series.recurring_occurrences+ .open_status+ .where.not(id: RecurringAllocation.select(:recurring_occurrence_id))+ doomed = removable.where("due_on >= ?", Date.current)+ doomed = doomed.or(removable.where(original_due_on: single_payment_moved_from)) if single_payment_moved_from++ doomed.delete_allgenerate!(through: through)end@@ -54,6 +63,24 @@ class RecurringTransactionendprivate+ def single_payment?+ series.ends_after_count? && series.end_after_count == 1+ end++ # The date a one-payment plan was just moved off, whose row the new date+ # replaces even when it is past. Every other past row is an obligation+ # from an earlier schedule, which a one-date schedule cannot recreate, so+ # it stays. Converting a repeating bill to Once is not a move: the cap is+ # already stored by the time regeneration runs, so the values from before+ # the save say whether it was a single payment already.+ def single_payment_moved_from+ return unless single_payment? && series.saved_change_to_anchor_date?+ return unless series.attribute_before_last_save("end_mode") == "after_count" &&+ series.attribute_before_last_save("end_after_count") == 1++ series.attribute_before_last_save("anchor_date")+ end+def default_horizon(schedule)horizon = Date.current + HORIZON_DAYSnext_due = schedule.first_occurrence_after(Date.current)@@ -107,6 +134,13 @@ class RecurringTransaction# beyond the window, so a kept row's nearest occurrence just outside it# is not mistaken for a farther one inside.def stood_in_for(schedule, from, through)+ # A Once bill is a date the user chose. Rows kept from an earlier+ # schedule are other obligations, not stand-ins for it, and a yearly+ # half cycle would let one swallow the new date. A one-payment+ # installment has no such date to protect, so its kept row still+ # stands in for the occurrence it was.+ return Set.new if single_payment? && !series.typed_installment?+reach = half_cycle(schedule)nearby = schedule.occurrence_pairs_between(from - reach, through + reach)current = nearby.map(&:original_due_on).to_setdiff --git a/app/models/recurring_transaction/paycheck_planner.rb b/app/models/recurring_transaction/paycheck_planner.rbindex b25df0ec9f..be2752464c 100644--- a/app/models/recurring_transaction/paycheck_planner.rb+++ b/app/models/recurring_transaction/paycheck_planner.rb@@ -143,9 +143,25 @@ class RecurringTransactiondates = incomes.map(&:due_on).uniq.first(periods_limit + 1)boundaries = ([ Date.current ] + dates).uniq+ # A period runs from one boundary to the next, so the last payday only+ # ends the window before it. A one-off with no payday after it would+ # never be credited, so it opens a window of its own. That window stops+ # at the horizon obligations are materialized through, so it never+ # counts bills nothing has stored yet. The payday itself always stays+ # inside it.+ if dates.size <= periods_limit && one_off_payday?(incomes, dates.last)+ materialized_through = Date.current + RecurringTransaction::OccurrenceGenerator::HORIZON_DAYS+ boundaries << [ materialized_through, dates.last + 1 ].max+ end+boundaries.first(periods_limit + 2)end+ def one_off_payday?(incomes, date)+ incomes.select { |occurrence| occurrence.due_on == date }+ .all? { |occurrence| occurrence.recurring_transaction.one_off? }+ end+def build_periods(boundaries, incomes)boundaries.each_cons(2).map.with_index do |(starts_on, next_start), index|arrivals = incomes.select { |occurrence| occurrence.due_on == starts_on }diff --git a/app/views/bills/_detail.html.erb b/app/views/bills/_detail.html.erbindex 05989222b7..f329776df3 100644--- a/app/views/bills/_detail.html.erb+++ b/app/views/bills/_detail.html.erb@@ -43,6 +43,9 @@<%= t("bills.detail.rule_learned_tolerance", percent: number_to_percentage(hints[:learned_pct], precision: 1, format: "%n%")) %></p><% end %>+ <% if series.one_off? %>+ <p class="text-xs text-secondary"><%= t("bills.detail.once_kind_hint") %></p>+ <% end %></div><%# What it has actually cost: the shape over twelve months, then the figures. %>@@ -54,7 +57,7 @@<div class="px-3 py-3 space-y-2"><% if analytics %>- <div class="grid grid-cols-3 gap-2">+ <div class="grid <%= series.one_off? ? "grid-cols-2" : "grid-cols-3" %> gap-2"><div><p class="text-xs text-secondary"><%= t("bills.detail.average") %></p><p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:average]) %></p>@@ -62,10 +65,12 @@<%= t("bills.detail.range", min: format_money(analytics[:lowest]), max: format_money(analytics[:highest])) %></p></div>- <div>- <p class="text-xs text-secondary"><%= t("bills.detail.annualized") %></p>- <p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:annualized]) %></p>- </div>+ <% unless series.one_off? %>+ <div>+ <p class="text-xs text-secondary"><%= t("bills.detail.annualized") %></p>+ <p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:annualized]) %></p>+ </div>+ <% end %><div><p class="text-xs text-secondary"><%= t("bills.detail.ytd") %></p><p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:ytd]) %></p>diff --git a/app/views/bills/all.html.erb b/app/views/bills/all.html.erbindex 5d093af09c..aa81c3ee23 100644--- a/app/views/bills/all.html.erb+++ b/app/views/bills/all.html.erb@@ -182,7 +182,9 @@<%# A monthly bill's monthly equivalent is its own amount, so thesecond line said "$5.99" under "$5.99". It only carriesinformation for the other cadences. %>- <% if monthly != amount %>+ <%# A one-off's monthly equivalent is zero, which would read as+ "$0/mo" under the real amount. %>+ <% if !series.one_off? && monthly != amount %><p class="text-xs text-secondary"><%= t(".monthly_equivalent", amount: format_money(monthly)) %></p><% end %><% end %>diff --git a/app/views/recurring_transactions/_form.html.erb b/app/views/recurring_transactions/_form.html.erbindex 0c78c0134d..fd9ae52281 100644--- a/app/views/recurring_transactions/_form.html.erb+++ b/app/views/recurring_transactions/_form.html.erb@@ -131,10 +131,25 @@</div></div>- <p class="text-xs text-secondary"><%= income ? t(".income_frequency_hint") : t(".frequency_hint") %></p>+ <div data-frequency-fields-target="group" data-presets="once" class="hidden">+ <%= f.date_field :frequency_once_on,+ label: income ? t(".income_once_on_label") : t(".once_on_label"),+ value: recurring_transaction.frequency_once_on || recurring_transaction.anchor_date || recurring_transaction.next_expected_date,+ required: true %>+ <p class="text-xs text-secondary mt-1"><%= income ? t(".income_once_hint") : t(".once_hint") %></p>+ </div>++ <div data-frequency-fields-target="group" data-presets="monthly,weekly,biweekly,semimonthly,quarterly,semiannual,annual,interval,custom" class="hidden">+ <p class="text-xs text-secondary"><%= income ? t(".income_frequency_hint") : t(".frequency_hint") %></p>+ </div><% else %><%# A new series' day details derive from its first date. %>- <p class="text-xs text-secondary"><%= income ? t(".income_frequency_new_hint") : t(".frequency_new_hint") %></p>+ <div data-frequency-fields-target="group" data-presets="monthly,weekly,biweekly,semimonthly,quarterly,semiannual,annual,interval,custom" class="hidden">+ <p class="text-xs text-secondary"><%= income ? t(".income_frequency_new_hint") : t(".frequency_new_hint") %></p>+ </div>+ <div data-frequency-fields-target="group" data-presets="once" class="hidden">+ <p class="text-xs text-secondary"><%= income ? t(".income_once_new_hint") : t(".once_new_hint") %></p>+ </div><% end %></div>diff --git a/config/locales/views/bills/en.yml b/config/locales/views/bills/en.ymlindex d2cd055848..cd9e1c1f19 100644--- a/config/locales/views/bills/en.yml+++ b/config/locales/views/bills/en.yml@@ -39,6 +39,7 @@ en:around: "around %{date}"overview: Overviewrules: How this bill is matched+ once_kind_hint: Mark the transaction as one-time to keep it out of your averages.rule_named: "%{name}"rule_amount_range: "from %{min} to %{max}"rule_aliases: "Also matches %{names}"diff --git a/config/locales/views/recurring_transactions/en.yml b/config/locales/views/recurring_transactions/en.ymlindex c6fa810734..67279d5f6f 100644--- a/config/locales/views/recurring_transactions/en.yml+++ b/config/locales/views/recurring_transactions/en.yml@@ -11,6 +11,7 @@ en:other: "Expected in %{count} days"day_of_month: Day %{day} of monthfrequency_presets:+ once: Oncemonthly: Monthlyweekly: Weeklybiweekly: Every 2 weeks@@ -32,6 +33,8 @@ en:quarterly: "Quarterly on the %{day}"semiannual: "Every 6 months on the %{day}"annual: "Yearly on %{month} %{day}"+ once: Once+ once_on: "Once on %{date}"every_n_weeks: "Every %{interval} weeks on %{weekday}"every_n_months: "Every %{interval} months on the %{day}"every_n_years: "Every %{interval} years on %{month} %{day}"@@ -147,6 +150,12 @@ en:frequency_new_hint: The day details come from the due date above. You can refine the schedule after saving.frequency_label: How oftenfrequency_hint: How often this bill comes due. Pick the day details to match your statement.+ once_on_label: Due on+ income_once_on_label: On+ once_hint: Due once, on this date. It will not repeat. Mark the transaction as one-time to keep it out of your averages.+ income_once_hint: Arrives once, on this date. It will not repeat. Mark the transaction as one-time to keep it out of your averages.+ once_new_hint: Due once, on the date above. It will not repeat. Mark the transaction as one-time to keep it out of your averages.+ income_once_new_hint: Arrives once, on the date above. It will not repeat. Mark the transaction as one-time to keep it out of your averages.frequency_day_label: On dayfrequency_interval_label: Repeats everyfrequency_interval_unit_label: Unit@@ -155,6 +164,7 @@ en:frequency_month_label: "In"update:success: Bill updated+ once_date_locked: This payment is already recorded, so its date can't be moved.success_with_siblings:one: "Bill updated, and the payment link was copied to 1 other bill"other: "Bill updated, and the payment link was copied to %{count} other bills"diff --git a/test/controllers/recurring_transactions/smart_fills_controller_test.rb b/test/controllers/recurring_transactions/smart_fills_controller_test.rbindex 6a3083054a..d920c64a21 100644--- a/test/controllers/recurring_transactions/smart_fills_controller_test.rb+++ b/test/controllers/recurring_transactions/smart_fills_controller_test.rb@@ -28,6 +28,20 @@ class RecurringTransactions::SmartFillsControllerTest < ActionDispatch::Integratassert_select "input[name=?][value=?]", "recurring_transaction[amount]", "42.00"end+ test "a one-off suggestion keeps the date of the charge it was read from" do+ charged_on = 20.days.ago.to_date+ entry = accounts(:depository).entries.create!(+ date: charged_on, amount: 320, currency: "USD", name: "CAR REGISTRATION", entryable: Transaction.new+ )+ stub_provider(raw(name: "Car registration", amount: 320.0, frequency: "once", confidence: 0.8))++ post smart_fill_recurring_transactions_url(entry_id: entry.id),+ headers: { "Turbo-Frame" => "modal" }++ assert_response :success+ assert_select "input[name=?][value=?]", "recurring_transaction[first_due_on]", charged_on.iso8601+ end+# Smart fill starts from the same prefill as the plain dialog, so the# transaction's category reaches the form here too.test "keeps the category of the transaction it starts from" dodiff --git a/test/controllers/recurring_transactions_controller_test.rb b/test/controllers/recurring_transactions_controller_test.rbindex f61c573598..1015a60258 100644--- a/test/controllers/recurring_transactions_controller_test.rb+++ b/test/controllers/recurring_transactions_controller_test.rb@@ -38,6 +38,8 @@ class RecurringTransactionsControllerTest < ActionDispatch::IntegrationTestassert_match "recurring_transaction[autopay]", bodyassert_match "recurring_transaction[notes]", bodyassert_match I18n.t("recurring_transactions.form.more_options"), body+ assert_match I18n.t("recurring_transactions.frequency_presets.once"), body+ assert_match I18n.t("recurring_transactions.form.once_new_hint"), bodyend# The amount is the money field every other form uses. On a new bill its@@ -729,6 +731,99 @@ class RecurringTransactionsControllerTest < ActionDispatch::IntegrationTestassert_equal 2, @family.recurring_transactions.where(name: "STREAMCO").countend+ test "creating a bill with frequency once schedules that date and no other" do+ due = Date.current + 20++ assert_difference "@family.recurring_transactions.count", 1 do+ post recurring_transactions_url, params: {+ recurring_transaction: {+ name: "Car registration",+ amount: "320",+ account_id: accounts(:depository).id,+ first_due_on: due.iso8601,+ frequency_preset: "once"+ }+ }+ end++ bill = @family.recurring_transactions.find_by!(name: "Car registration")+ assert bill.one_off?+ assert_equal due, bill.anchor_date+ assert_equal due, bill.next_expected_date+ assert_equal [ due ], bill.recurring_occurrences.reload.pluck(:due_on)+ assert_empty bill.schedule.occurrences_between(due + 1, due + 400)++ get edit_recurring_transaction_url(bill), headers: { "Turbo-Frame" => "modal" }+ assert_response :success+ assert_select "option[selected][value=?]", "once"+ assert_select "input[name=?][value=?]", "recurring_transaction[frequency_once_on]", due.iso8601++ get bill_url(bill, display: "history"),+ headers: { "Turbo-Frame" => ActionView::RecordIdentifier.dom_id(bill, :history) }+ assert_response :success+ assert_match I18n.t("bills.detail.once_kind_hint"), response.body+ end++ test "a one-off dated in the past still materializes, and its date can move" do+ due = Date.current - 3++ post recurring_transactions_url, params: {+ recurring_transaction: {+ name: "School fee", amount: "80", first_due_on: due.iso8601, frequency_preset: "once"+ }+ }++ bill = @family.recurring_transactions.find_by!(name: "School fee")+ assert_equal [ due ], bill.recurring_occurrences.reload.pluck(:due_on)++ moved = Date.current + 12+ patch recurring_transaction_url(bill), params: {+ recurring_transaction: { frequency_preset: "once", frequency_once_on: moved.iso8601 }+ }++ assert_equal [ moved ], bill.recurring_occurrences.reload.pluck(:due_on)+ assert_equal moved, bill.reload.next_expected_date+ end++ test "switching a repeating bill to once without a date uses its current due date" do+ due = Date.current + 5+ post recurring_transactions_url, params: {+ recurring_transaction: { name: "Tuition", amount: "900", first_due_on: due.iso8601, frequency_preset: "monthly" }+ }+ bill = @family.recurring_transactions.find_by!(name: "Tuition")+ stale = Date.current - 200+ bill.update_columns(anchor_date: stale)++ get edit_recurring_transaction_url(bill), headers: { "Turbo-Frame" => "modal" }+ assert_select "input[name=?][value=?]", "recurring_transaction[frequency_once_on]", due.iso8601++ # What Smart Configure submits: the preset alone, with no date.+ patch recurring_transaction_url(bill), params: { recurring_transaction: { frequency_preset: "once" } }++ assert_equal due, bill.reload.anchor_date+ assert_equal [ due ], bill.recurring_occurrences.reload.pluck(:due_on)+ end++ test "moving a paid one-off is refused and does not add a second occurrence" do+ due = Date.current + 4++ post recurring_transactions_url, params: {+ recurring_transaction: {+ name: "Registration", amount: "80", first_due_on: due.iso8601, frequency_preset: "once"+ }+ }+ bill = @family.recurring_transactions.find_by!(name: "Registration")+ RecurringTransaction::Allocator.new(bill.recurring_occurrences.find_by!(due_on: due)).mark_paid!++ patch recurring_transaction_url(bill), params: {+ recurring_transaction: { frequency_preset: "once", frequency_once_on: (due + 30).iso8601 }+ }++ assert_response :unprocessable_entity+ assert_equal due, bill.reload.anchor_date+ assert_equal [ due ], bill.recurring_occurrences.reload.pluck(:due_on)+ end+test "marking a bill as an installment plan caps its occurrences and tracks progress" dodue = Date.current + 5post recurring_transactions_url, params: {diff --git a/test/models/assistant/function/create_bill_test.rb b/test/models/assistant/function/create_bill_test.rbindex d7e420b501..4825430b7b 100644--- a/test/models/assistant/function/create_bill_test.rb+++ b/test/models/assistant/function/create_bill_test.rb@@ -26,6 +26,22 @@ class Assistant::Function::CreateBillTest < ActiveSupport::TestCaseassert_operator series.recurring_occurrences.count, :>, 0end+ test "frequency once creates a single occurrence on the due date" do+ due = Date.current + 40++ result = call_tool(+ "name" => "Domain renewal", "amount" => 18, "first_due_on" => due.iso8601,+ "frequency" => "once"+ )++ assert result[:created]+ assert_equal [ due.iso8601 ], result[:upcoming_due_dates]++ series = @family.recurring_transactions.find_by!(name: "Domain renewal")+ assert series.one_off?+ assert_equal [ due ], series.recurring_occurrences.pluck(:due_on)+ end+test "income flips the stored sign, never the caller's" doresult = call_tool("name" => "Paycheck", "amount" => 1200,diff --git a/test/models/assistant/function/update_bill_test.rb b/test/models/assistant/function/update_bill_test.rbindex 4603a62099..02755d8b17 100644--- a/test/models/assistant/function/update_bill_test.rb+++ b/test/models/assistant/function/update_bill_test.rb@@ -154,6 +154,22 @@ class Assistant::Function::UpdateBillTest < ActiveSupport::TestCaseassert_match(/More than one account/, result[:error])end+ test "frequency once lands on the current due date, not the original anchor" do+ series = create_series(name: "Tuition", amount: 500)+ current_due = series.next_due_date+ stale_anchor = current_due - 200+ series.update_columns(anchor_date: stale_anchor)++ result = call_tool(series.id, "frequency" => "once")++ assert result[:updated], result[:error]+ series.reload+ assert_equal current_due, series.anchor_date+ assert_includes series.recurring_occurrences.pluck(:due_on), current_due+ assert_not_includes series.recurring_occurrences.pluck(:due_on), stale_anchor+ assert_empty series.recurring_occurrences.where("due_on > ?", current_due)+ end+test "an unrecognized frequency is rejected before anything saves" doseries = create_series(name: "Insurance", amount: 60)diff --git a/test/models/recurring_transaction/frequency_preset_test.rb b/test/models/recurring_transaction/frequency_preset_test.rbindex 08c96df287..28b7c2151b 100644--- a/test/models/recurring_transaction/frequency_preset_test.rb+++ b/test/models/recurring_transaction/frequency_preset_test.rb@@ -215,6 +215,114 @@ class RecurringTransaction::FrequencyPresetTest < ActiveSupport::TestCaseassert_equal 8, @recurring.recurrence_rules.reload.sole.interval, "a leading zero is not octal"end+ test "once is a single occurrence on the chosen date and not a monthly rate" do+ due = Date.new(2026, 12, 1)++ assert Preset.apply(@recurring, preset: "once", once_on: due)+ @recurring.save!++ rule = @recurring.recurrence_rules.reload.sole+ assert_equal [ "yearly", 1, 1, 12 ], [ rule.frequency, rule.interval, rule.day_of_month, rule.month_of_year ]+ assert @recurring.ends_after_count?+ assert_equal 1, @recurring.end_after_count+ assert_equal due, @recurring.anchor_date+ assert_equal due, @recurring.next_expected_date+ assert @recurring.one_off?+ assert_equal 0, @recurring.monthly_equivalent_amount.amount++ found = Preset.detect(@recurring)+ assert_equal [ "once", due ], [ found.key, found.once_on ]+ assert_equal I18n.t("recurring_transactions.frequency.once_on", date: I18n.l(due, format: :long)),+ Preset.label(@recurring)++ assert_equal [ due ], @recurring.schedule.occurrences_between(due, due + 400)+ assert_not Preset.apply(@recurring, preset: "once", once_on: due.iso8601),+ "reapplying the same date must change nothing"+ end++ test "once rejects a date that was typed but cannot be parsed" do+ assert_not Preset.apply(@recurring, preset: "once", once_on: "2026-13-40")+ assert_includes @recurring.errors.full_messages,+ I18n.t("recurring_transactions.create.due_date_required")+ assert_empty @recurring.recurrence_rules+ end++ test "moving a paid one-off is refused and leaves the schedule untouched" do+ due = Date.new(2026, 12, 1)+ Preset.apply(@recurring, preset: "once", once_on: due)+ @recurring.save!+ RecurringTransaction::Allocator.new(@recurring.recurring_occurrences.find_by!(due_on: due)).mark_paid!++ assert_not Preset.apply(@recurring, preset: "once", once_on: due + 10)+ assert_includes @recurring.errors.full_messages,+ I18n.t("recurring_transactions.update.once_date_locked")+ assert_equal due, @recurring.reload.anchor_date+ assert_equal "once", Preset.detect(@recurring).key+ end++ test "changing a paid one-off to an installment does not unlock its date" do+ due = Date.new(2026, 12, 1)+ Preset.apply(@recurring, preset: "once", once_on: due)+ @recurring.save!+ RecurringTransaction::Allocator.new(@recurring.recurring_occurrences.find_by!(due_on: due)).mark_paid!++ @recurring.bill_type = "installment"++ assert_not Preset.apply(@recurring, preset: "once", once_on: due + 10)+ assert_includes @recurring.errors.full_messages,+ I18n.t("recurring_transactions.update.once_date_locked")+ assert_equal due, @recurring.reload.anchor_date+ end++ test "an earlier paid occurrence does not lock a one-off's date" do+ travel_to Date.new(2026, 11, 13) do+ RecurringTransaction::OccurrenceGenerator.new(@recurring).generate!+ earlier = @recurring.recurring_occurrences.reload.find_by!(due_on: Date.new(2026, 11, 5))+ RecurringTransaction::Allocator.new(earlier).mark_paid!++ Preset.apply(@recurring, preset: "once", once_on: Date.new(2026, 12, 1))+ @recurring.save!++ assert Preset.apply(@recurring, preset: "once", once_on: Date.new(2026, 12, 20))+ assert_empty @recurring.errors+ end+ end++ test "once without a date is due on the bill's current due date, not its first" do+ stale = Date.new(2026, 1, 5)+ @recurring.update_columns(anchor_date: stale)+ due = @recurring.next_due_date++ assert Preset.apply(@recurring, preset: "once")++ assert_equal due, @recurring.anchor_date+ assert_equal due, @recurring.next_expected_date+ end++ test "leaving once drops the one-payment cap" do+ due = Date.new(2026, 12, 1)+ Preset.apply(@recurring, preset: "once", once_on: due)+ @recurring.save!++ assert Preset.apply(@recurring, preset: "monthly", day_of_month: due.day.to_s)+ @recurring.save!+ @recurring.reload++ assert @recurring.ends_never?+ assert_nil @recurring.end_after_count+ assert_equal "monthly", Preset.detect(@recurring).key+ assert_operator @recurring.schedule.occurrences_between(due, due + 70).size, :>, 1+ end++ test "a one-payment installment stays an installment, not a one-off" do+ @recurring.update!(bill_type: "installment", end_mode: "after_count", end_after_count: 1,+ anchor_date: Date.new(2026, 12, 1))+ @recurring.recurrence_rules.create!(frequency: "yearly", day_of_month: 1, month_of_year: 12)++ assert_equal "annual", Preset.detect(@recurring.reload).key+ assert_not @recurring.one_off?+ end+test "apply interval rejects an out-of-range, fractional or malformed count or an unknown unit" do[ [ "0", "weekly" ], [ "", "monthly" ], [ (Preset::MAX_INTERVAL + 1).to_s, "monthly" ], [ "2", "daily" ],[ "2.5", "monthly" ], [ "3abc", "weekly" ] ].each do |interval, unit|diff --git a/test/models/recurring_transaction/occurrence_generator_test.rb b/test/models/recurring_transaction/occurrence_generator_test.rbindex b544e50ab9..34953cd28a 100644--- a/test/models/recurring_transaction/occurrence_generator_test.rb+++ b/test/models/recurring_transaction/occurrence_generator_test.rb@@ -56,6 +56,93 @@ class RecurringTransaction::OccurrenceGeneratorTest < ActiveSupport::TestCaseendend+ test "converting a repeating bill to once keeps unpaid past occurrences and adds the one date" do+ travel_to Date.new(2026, 11, 13) do+ Generator.new(@series).generate!+ past = @series.recurring_occurrences.create!(+ family: @family, original_due_on: Date.new(2026, 9, 5), due_on: Date.new(2026, 9, 5),+ currency: "USD", status: "scheduled"+ )++ RecurringTransaction::FrequencyPreset.apply(@series, preset: "once", once_on: Date.new(2026, 12, 1))+ @series.save!++ dues = @series.recurring_occurrences.reload.pluck(:due_on)+ assert_includes dues, past.due_on, "an earlier unpaid bill is still owed"+ assert_includes dues, Date.new(2026, 11, 5), "the overdue occurrence from the old schedule stays"+ assert_includes dues, Date.new(2026, 12, 1), "the one date is scheduled beside those"+ assert_not_includes dues, Date.new(2026, 12, 5), "later repeating dates are rebuilt away"+ end+ end++ test "moving an unpaid one-off still replaces its past date" do+ travel_to Date.new(2026, 11, 13) do+ due = Date.new(2026, 11, 1)+ RecurringTransaction::FrequencyPreset.apply(@series, preset: "once", once_on: due)+ @series.save!+ assert_equal [ due ], @series.recurring_occurrences.reload.pluck(:due_on)++ moved = Date.new(2026, 12, 1)+ RecurringTransaction::FrequencyPreset.apply(@series, preset: "once", once_on: moved)+ @series.save!++ assert_equal [ moved ], @series.recurring_occurrences.reload.pluck(:due_on)+ end+ end++ test "moving a one-off drops only its own date and keeps overdue rows from the repeating schedule" do+ travel_to Date.new(2026, 11, 13) do+ Generator.new(@series).generate!+ overdue = @series.recurring_occurrences.reload.find_by!(due_on: Date.new(2026, 11, 5))++ RecurringTransaction::FrequencyPreset.apply(@series, preset: "once", once_on: Date.new(2026, 12, 1))+ @series.save!+ RecurringTransaction::FrequencyPreset.apply(@series, preset: "once", once_on: Date.new(2026, 12, 20))+ @series.save!++ dues = @series.recurring_occurrences.reload.pluck(:due_on)+ assert_includes dues, overdue.due_on, "the earlier unpaid bill is still owed"+ assert_includes dues, Date.new(2026, 12, 20), "an old row nearby must not stand in for the new date"+ assert_not_includes dues, Date.new(2026, 12, 1), "the date it moved off is replaced"+ end+ end++ test "a one-payment installment moved by a day keeps its paid row standing in for the payment" do+ travel_to Date.new(2026, 8, 13) do+ installment = @family.recurring_transactions.create!(+ name: "Sofa plan", amount: 120, currency: "USD", bill_type: "installment",+ account: accounts(:depository), anchor_date: Date.new(2026, 8, 20), expected_day_of_month: 20,+ last_occurrence_date: Date.new(2026, 8, 20), next_expected_date: Date.new(2026, 8, 20),+ status: "active", manual: true, end_mode: "after_count", end_after_count: 1,+ dedup_scope: "sofa-plan"+ )+ installment.recurrence_rules.create!(frequency: "monthly", interval: 1, day_of_month: 20)+ Generator.new(installment).generate!+ paid = installment.recurring_occurrences.reload.find_by!(due_on: Date.new(2026, 8, 20))+ RecurringTransaction::Allocator.new(paid).mark_paid!++ RecurringTransaction::FrequencyPreset.apply(installment, preset: "monthly", day_of_month: "21")+ installment.save!++ # Generate from a fresh read of the series, as the nightly sweep does.+ Generator.new(RecurringTransaction.find(installment.id)).generate!+ open_dues = installment.recurring_occurrences.reload.open_status.pluck(:due_on)+ assert_empty open_dues, "the paid payment stands in for the moved one; no second obligation appears"+ end+ end++ test "pausing an overdue one-off keeps its row" do+ travel_to Date.new(2026, 11, 13) do+ due = Date.new(2026, 11, 1)+ RecurringTransaction::FrequencyPreset.apply(@series, preset: "once", once_on: due)+ @series.save!++ @series.update!(status: "paused")++ assert_equal [ due ], @series.recurring_occurrences.reload.pluck(:due_on)+ end+ end+test "pausing prunes the re-generatable future and resuming rebuilds it" dotravel_to Date.new(2026, 8, 13) doGenerator.new(@series).generate!diff --git a/test/models/recurring_transaction/paycheck_planner_test.rb b/test/models/recurring_transaction/paycheck_planner_test.rbindex 42d9576529..df43a77033 100644--- a/test/models/recurring_transaction/paycheck_planner_test.rb+++ b/test/models/recurring_transaction/paycheck_planner_test.rb@@ -10,6 +10,39 @@ class RecurringTransaction::PaycheckPlannerTest < ActiveSupport::TestCase@family.recurring_transactions.destroy_allend+ test "a lone one-off income is credited in a window of its own" do+ payday = Date.current + 6+ create_series(name: "Bonus", amount: -3000, due: payday, preset: "once", income: true)+ create_series(name: "Insurance", amount: 400, due: payday + 3, preset: "once")++ plan = Planner.new(@family, user: @user).plan(periods_limit: 3)++ assert_equal [ Date.current, payday ], plan.map(&:starts_on)+ assert_equal 3000, plan.last.income+ assert_equal [ "Bonus" ], plan.last.income_sources+ assert_equal 400, plan.last.due_total, "a bill after the one-off is funded from it"+ end++ test "a one-off income far ahead keeps its payday in a window that ends at its own date" do+ payday = Date.current + 200+ create_series(name: "Bonus", amount: -3000, due: payday, preset: "once", income: true)++ plan = Planner.new(@family, user: @user).plan(periods_limit: 3)++ assert_equal payday, plan.last.starts_on+ assert_equal payday, plan.last.ends_on, "nothing past the payday is materialized for this window"+ assert_equal 3000, plan.last.income+ end++ test "a one-off income arriving today still makes a plan" do+ create_series(name: "Bonus", amount: -3000, due: Date.current, preset: "once", income: true)++ plan = Planner.new(@family, user: @user).plan(periods_limit: 3)++ assert_equal 1, plan.size+ assert_equal 3000, plan.first.income+ end+test "no declared income means no plan" docreate_series(name: "Rent", amount: 2150, due: Date.current + 10)@@ -501,7 +534,8 @@ class RecurringTransaction::PaycheckPlannerTest < ActiveSupport::TestCase)if preset != "monthly"- RecurringTransaction::FrequencyPreset.apply(series, preset: preset, weekday: due.wday)+ RecurringTransaction::FrequencyPreset.apply(series, preset: preset, weekday: due.wday,+ once_on: (due if preset == "once"))series.save!end