-
Notifications
You must be signed in to change notification settings - Fork 275
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
Adding bill types and automatic settling between people #1290
Conversation
… to reflect the behavior
bill attribute added
eliminating unnecessary bill type
typo fixed, test cases fixed for the current bill types
…e-button Yiqunz settle button
…-test test cases added
…ll-type-tests Added tests for new bill types
…-test test cases fixed
Tests are currently failing on postgres, because it tries to use a unknown type:
(The tests run otherwise properly when using sqlite) |
Oh weird, I'll have a look this weekend to see why it's doing that. |
Alembic does not handle postgres Enums correctly, so we need to manually generate the new enum type. See sqlalchemy/alembic#278
Turns out alembic does not handle the generation of new enums correctly for postgres databases. See this issue. I fixed it by manually creating the sqlalchemy enum in the upgrade step of the migration, as someone suggested in the issue I linked. In that issue someone also introduced a library that handles enum migrations in alembic automatically: alemibc-postgresql-enum, but I didn't want to add a new dependency for this small issue :). Hopefully the tests are green now! It seemed to work on a postgres database I spun up locally. |
Perfect, thanks :-) |
Thanks for the work on this 👍 |
It was a pleasure to work with you :-) |
Same here! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for finishing this long-awaited feature!
I'm a bit late to the party, I have added some comments, they can be addressed in a new pull request.
By the way, black is also complaining about formatting (see the CI output)
"bill_type": "Transfer", | ||
"amount": "500", | ||
}, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a leftover of the "Transfer" type
"what": "Transfer of 500 to fred", | ||
"payer": members_ids[0], #zorglub | ||
"payed_for": members_ids[1], #fred | ||
"bill_type": "Transfer", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
@@ -848,6 +850,27 @@ def settle_bill(): | |||
return render_template("settle_bills.html", bills=bills, current_view="settle_bill") | |||
|
|||
|
|||
@main.route("/<project_id>/settle/<amount>/<int:ower_id>/<int:payer_id>") | |||
def settle(amount, ower_id, payer_id): | |||
# FIXME: Test this bill belongs to this project ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it should really be fixed! (and a test added for good measure)
@@ -536,7 +560,8 @@ def test_export_with_currencies(self): | |||
}, | |||
{ | |||
"date": "2016-12-31", | |||
"what": "fromage \xe0 raclette", | |||
"what": "\xe0 raclette", | |||
"bill_type": "Expense", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take it you don't like fromage? ;)
@@ -848,6 +850,27 @@ def settle_bill(): | |||
return render_template("settle_bills.html", bills=bills, current_view="settle_bill") | |||
|
|||
|
|||
@main.route("/<project_id>/settle/<amount>/<int:ower_id>/<int:payer_id>") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, there is no test for this new route. We should have one.
Sure, I'll go through those comments and submit a new PR! I'll probably have time to have a look in the weekend, though no promises. You just use python-black on the whole codebase? Then I'll make sure to run it along with the suggested changes. |
Error introduced in spiral-project#1290.
Error introduced in spiral-project#1290. Fixes spiral-project#1293.
Error introduced in spiral-project#1290. Fixes spiral-project#1293.
Error introduced in spiral-project#1290. Fixes spiral-project#1293.
Error introduced in spiral-project#1290. Fixes spiral-project#1293.
Fixes the following flake8 issue: ihatemoney/tests/budget_test.py:880:5: F811 redefinition of unused 'test_reimbursement_bill' from line 796 ihatemoney/tests/budget_test.py:930:5: F811 redefinition of unused 'test_transfer_bill' from line 846 PR spiral-project#1290 introduced these tests twice.
Error introduced in spiral-project#1290. Fixes spiral-project#1293.
Error introduced in spiral-project#1290. Fixes spiral-project#1293.
Error introduced in spiral-project#1290. Fixes spiral-project#1293. WTForms needs to be bumped to >=2.3.2 as it includes a fix to `SelectField` which is required for this change to work. See: - https://wtforms.readthedocs.io/en/3.1.x/changes/#version-2-3-2 - pallets-eco/wtforms#598
Error introduced in #1290. Fixes #1293. WTForms needs to be bumped to >=2.3.2 as it includes a fix to `SelectField` which is required for this change to work. See: - https://wtforms.readthedocs.io/en/3.1.x/changes/#version-2-3-2 - pallets-eco/wtforms#598
Summary
This PR is a continuation of #1116. The goal of this PR is to finish the work of the original PR and fix #137. The overall design changes proposed in #1116 are mostly kept, though I'll detail the changes below. This PR adds a button to the "Settle" page to automatically let users signify they have settled their debt with other people. This generates a new bill in the overview page that will bring their debt with that person to 0.
Normally this would pollute the statistics of that project, so a bill_type column is added to the database. There are 2 types, "Reimbursement" and "Expense", only the latter is used to calculate the total cost of the project.
Changes since the original PR
Open questions
With these changes, all bill creation requests to the API require that a "bill_type" is provided. This will break compatibility with apps using the API. Should we make the "bill_type" field an optional parameter? I think we can safely make the default type be "Expense".