mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Add support for manual recurring transaction creation (#311)
* Support manual recurring * Automatic variance calc * Automatic variance update * Tooltip for manual * Review * Fix variance calculations Manual recurring updates collapse occurrence tracking when amounts repeat * Proper Bigdecimal calcs * Fix n+1 query * Nicer UI errors. * Style --------- Signed-off-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
@@ -6,18 +6,19 @@ class RecurringTransaction
|
||||
@family = family
|
||||
end
|
||||
|
||||
# Mark recurring transactions as inactive if they haven't occurred in 2+ months
|
||||
# Mark recurring transactions as inactive if they haven't occurred recently
|
||||
# Uses 2 months for automatic recurring, 6 months for manual recurring
|
||||
def cleanup_stale_transactions
|
||||
two_months_ago = 2.months.ago.to_date
|
||||
|
||||
stale_transactions = family.recurring_transactions
|
||||
.active
|
||||
.where("last_occurrence_date < ?", two_months_ago)
|
||||
|
||||
stale_count = 0
|
||||
stale_transactions.find_each do |recurring_transaction|
|
||||
|
||||
family.recurring_transactions.active.find_each do |recurring_transaction|
|
||||
next unless recurring_transaction.should_be_inactive?
|
||||
|
||||
# Determine threshold based on manual flag
|
||||
threshold = recurring_transaction.manual? ? 6.months.ago.to_date : 2.months.ago.to_date
|
||||
|
||||
# Double-check if there are any recent matching transactions
|
||||
recent_matches = recurring_transaction.matching_transactions.select { |entry| entry.date >= two_months_ago }
|
||||
recent_matches = recurring_transaction.matching_transactions.select { |entry| entry.date >= threshold }
|
||||
|
||||
if recent_matches.empty?
|
||||
recurring_transaction.mark_inactive!
|
||||
@@ -29,11 +30,13 @@ class RecurringTransaction
|
||||
end
|
||||
|
||||
# Remove inactive recurring transactions that have been inactive for 6+ months
|
||||
# Manual recurring transactions are never automatically deleted
|
||||
def remove_old_inactive_transactions
|
||||
six_months_ago = 6.months.ago
|
||||
|
||||
family.recurring_transactions
|
||||
.inactive
|
||||
.where(manual: false)
|
||||
.where("updated_at < ?", six_months_ago)
|
||||
.destroy_all
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user