Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Budget split for transactions - Model Refactor #105

Closed
8 tasks done
jantman opened this issue Aug 5, 2017 · 12 comments
Closed
8 tasks done

Budget split for transactions - Model Refactor #105

jantman opened this issue Aug 5, 2017 · 12 comments
Assignees

Comments

@jantman
Copy link
Owner

jantman commented Aug 5, 2017

This is part 1 of 2 to add support for allocating a single transaction against multiple budgets. This must maintain the actual transaction amount (for OFX reconcile, etc.) but allow allocating that amount either to one budget, or split across multiple budgets.

Planning:

  • Figure out how to handle a Transaction's budgeted_amount if we're now going to allow budget splits.

Implementation:

  • Add another model, BudgetTransaction, that builds an association between a transaction, an amount that's part or all of that transaction, and a budget. Fields should probably be ID, trans_id / transaction relationship, budget_id / budget relationship, and amount.
  • Transaction model gets a backref to a list of BudgetTransactions.
  • Database migration for this. Adds the new table and the relation to the Transaction table, migrates (copies) the data.
  • Code updates to make all of that work, including update to Transaction creation and editing.
  • Ensure ScheduledTransaction to Transaction conversion works correctly
  • Alter the database migration previously created to drop the Transaction.budget_id column.
  • Test the database migrations using a small sample database. Maybe try testing them in both directions?
@jantman jantman added the ready label Aug 6, 2017
@jantman jantman added ready and removed ready labels Aug 21, 2017
@jantman
Copy link
Owner Author

jantman commented Nov 11, 2017

Maybe better than doing all the work it would take to retrofit this, we should add transaction Categories in addition to budgets... where budgets would be for... well... budgeting, and categories would be solely for reporting. That would make implementation easier, and we could setup default categories for each budget, but is this a good idea?

@jantman
Copy link
Owner Author

jantman commented Jan 8, 2018

Categories is probably a bad idea. It's a hack-y way around the complexity of the problem, that ends up complicating the UX and not really solving the problem.

I think the logical implementation is a BudgetTransaction model:

  • id
  • trans_id / transaction
  • budget_id / budget
  • amount

The Transaction model should get backref relationships to a list of BudgetTransactions.

The UI will handle validation of this, but we should also have some DB-side validation that ensures all BudgetTransaction amount sums equal the Transaction amount.

We'll want to remove the budget field on the Transaction itself, and then update the codebase to work with the new models.

We'll also need a migration for this that adds the new table and the relation to the Transaction table, migrates the data, and then drops the old columns.

@jantman
Copy link
Owner Author

jantman commented Jan 12, 2018

Updated the initial comment/description of the issue with the current plan of work.

jantman added a commit that referenced this issue Jan 14, 2018
jantman added a commit that referenced this issue Jan 14, 2018
jantman added a commit that referenced this issue Jan 14, 2018
@jantman
Copy link
Owner Author

jantman commented Jan 14, 2018

Updated the checklist again. I started some implementation for this in the noci-issues/105 branch, but forgot about the budgeted_amount field on Transaction and need to figure out how to handle that, and how to handle the budget associated with it. Not sure if that should be part of the Transaction model or the BudgetTransaction model.

jantman added a commit that referenced this issue Jan 21, 2018
jantman added a commit that referenced this issue Jan 21, 2018
jantman added a commit that referenced this issue Jan 21, 2018
@jantman
Copy link
Owner Author

jantman commented Feb 5, 2018

So regarding the last comment on budgeted_amount... I think the solution to this is to add a planned_budget field on the Transaction and use that, along with budgeted_amount.

So a Transaction will have values for planned_budget / planned_budget_id and budgeted_amount set by the ScheduledTransaction, and then the related BudgetTransaction instances to describe the actual amount(s).

@jantman jantman changed the title Budget split for transactions Budget split for transactions - Model Refactor Feb 6, 2018
jantman added a commit that referenced this issue Feb 6, 2018
jantman added a commit that referenced this issue Feb 8, 2018
jantman added a commit that referenced this issue Feb 18, 2018
…ounts() instead of direct BudgetTransaction() creation
jantman added a commit that referenced this issue Feb 18, 2018
jantman added a commit that referenced this issue Feb 18, 2018
jantman added a commit that referenced this issue Feb 18, 2018
jantman added a commit that referenced this issue Feb 23, 2018
jantman added a commit that referenced this issue Feb 23, 2018
@jantman
Copy link
Owner Author

jantman commented Feb 23, 2018

As of the above commit, this issue should finally be complete aside from testing the DB migrations.

I'll probably just write a one-off script to handle that.

Or, maybe if I really care, I'll combine the auto-migration logic with the DB refreshing test logic, and write a sample class for testing DB forward and reverse migrations.

jantman added a commit that referenced this issue Feb 24, 2018
jantman added a commit that referenced this issue Feb 24, 2018
…m f136418fc4ab and 5446559aecf7 we ended up with an index in the migrations but not the model
jantman added a commit that referenced this issue Feb 24, 2018
jantman added a commit that referenced this issue Feb 24, 2018
jantman added a commit that referenced this issue Feb 24, 2018
jantman added a commit that referenced this issue Feb 24, 2018
jantman added a commit that referenced this issue Feb 24, 2018
jantman added a commit that referenced this issue Feb 24, 2018
@jantman jantman self-assigned this Feb 24, 2018
@jantman jantman added in progress and removed ready labels Feb 24, 2018
@jantman jantman reopened this Mar 4, 2018
@jantman
Copy link
Owner Author

jantman commented Jul 7, 2018

Released today in 1.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant