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

Adding bill types and automatic settling between people #1290

Merged
merged 40 commits into from
Mar 16, 2024

Conversation

TomRoussel
Copy link
Contributor

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

  • Brought the FlowingCloudRTL branch up to speed with the current master
  • Worked in the minor suggested changes by @Glandos
  • Changed the "bill_type" column to use an Enum (as requested by @Glandos). This enum is also used by the bill form validator
  • Removed the "Transfer" bill type. Personally I don't see a use for it and it seems confusing to the user. In the original PR, there didn't seem to be any interest in keeping it around
  • Added an api test to check if bill_type is validated correctly

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".

Ruitao Li and others added 30 commits December 10, 2022 22:14
typo fixed, test cases fixed for the current bill types
…ll-type-tests

Added tests for new bill types
@almet
Copy link
Member

almet commented Mar 15, 2024

Tests are currently failing on postgres, because it tries to use a unknown type:

psycopg2.errors.UndefinedObject: type "billtype" does not exist
E       LINE 1: ALTER TABLE bill ADD COLUMN bill_type billtype DEFAULT 'EXPE...

(The tests run otherwise properly when using sqlite)

@TomRoussel
Copy link
Contributor Author

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
@TomRoussel
Copy link
Contributor Author

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.

@almet
Copy link
Member

almet commented Mar 16, 2024

Perfect, thanks :-)

@almet almet merged commit 720f0e5 into spiral-project:master Mar 16, 2024
15 of 17 checks passed
@almet
Copy link
Member

almet commented Mar 16, 2024

Thanks for the work on this 👍

@almet
Copy link
Member

almet commented Mar 16, 2024

It was a pleasure to work with you :-)

@TomRoussel
Copy link
Contributor Author

Same here!

@TomRoussel TomRoussel deleted the bill_types_settle branch March 16, 2024 11:45
Copy link
Collaborator

@zorun zorun left a 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",
},
)
Copy link
Collaborator

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",
Copy link
Collaborator

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 !
Copy link
Collaborator

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",
Copy link
Collaborator

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>")
Copy link
Collaborator

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.

@TomRoussel
Copy link
Contributor Author

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.

rriski added a commit to rriski/ihatemoney that referenced this pull request Mar 23, 2024
rriski added a commit to rriski/ihatemoney that referenced this pull request Mar 23, 2024
rriski added a commit to rriski/ihatemoney that referenced this pull request Mar 23, 2024
rriski added a commit to rriski/ihatemoney that referenced this pull request Mar 23, 2024
rriski added a commit to rriski/ihatemoney that referenced this pull request Mar 24, 2024
rriski added a commit to rriski/ihatemoney that referenced this pull request Mar 24, 2024
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.
rriski added a commit to rriski/ihatemoney that referenced this pull request Mar 26, 2024
rriski added a commit to rriski/ihatemoney that referenced this pull request Mar 26, 2024
rriski added a commit to rriski/ihatemoney that referenced this pull request Mar 28, 2024
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
  - wtforms/wtforms#598
zorun pushed a commit that referenced this pull request Mar 28, 2024
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
  - wtforms/wtforms#598
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

Successfully merging this pull request may close these issues.

Add the ability to pay from the "settle" page
7 participants