scottohara / loot

An implementation of some of the core MS Money features in Ruby on Rails
MIT License
4 stars 3 forks source link

Auto-cleanup payees/categories that have no transactions #107

Open scottohara opened 8 years ago

scottohara commented 8 years ago

A common scenario is to enter a transaction from a receipt with a merchant like "XYZ Holdings Pty Ltd"; only to later discover the commonly known trading name for that business (eg. "Bob's Pizza's").

When the transaction was created, we automatically create "XYZ Holdings Pty Ltd" as a payee (assuming we've never seen them before); and later when we edit the transaction's payee to "Bob's Pizza's", it creates another new payee.

The original payee ("XYZ Holdings") now has no transactions associated with it; so we no longer need to keep it in the database.

Effectively, we want to "ref count" payees/categories/securities; and when the ref count drops to zero (ie. not referenced by any transactions), delete it.

We could potentially do this on transaction save (note that if the transaction type changes, we delete & reinsert; so we would need to snapshot the original details before deleting, so that we can determine what to cleanup afterwards).

Or, like we do with scheduled transactions; we could run a process as part of the login that detects any orphaned entries and cleans them up (the downside there is that we slowdown login).

Or, we use this as an opportunity (perhaps as part of the Rails 5 upgrade...ie. ActiveJob) to look at introducing background processing

scottohara commented 4 years ago

Or, like we do with scheduled transactions; we could run a process as part of the login that detects any orphaned entries and cleans them up (the downside there is that we slowdown login).

Or we do it when the Payees/Categories List is displayed, with a toast or banner showing at the top of the page, e.g.

"There are 3 payees that have no no associated transactions. Would you like to remove them? Yes | No"

scottohara commented 3 years ago

For now, we have Heroku data clips that show us any orphaned payees/categories