diff options
| author | dark0dave <52840419+dark0dave@users.noreply.github.com> | 2020-04-29 21:57:08 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-04-29 22:57:08 +0200 |
| commit | f389c562595f74bea86e49c29949f4a7b0e78900 (patch) | |
| tree | c3c0ac339ad002f47e2be9cd3a46d347012b1d70 /ihatemoney/web.py | |
| parent | 162193c787341118621b36b4c8933bbe8af092df (diff) | |
| download | ihatemoney-mirror-f389c562595f74bea86e49c29949f4a7b0e78900.zip ihatemoney-mirror-f389c562595f74bea86e49c29949f4a7b0e78900.tar.gz ihatemoney-mirror-f389c562595f74bea86e49c29949f4a7b0e78900.tar.bz2 | |
Feature/currencies (#541)
Now each project can have a currency, default to None.
Each bill can use a different currency, and a conversion to project default currency is done on settle.
Fix #512
Diffstat (limited to 'ihatemoney/web.py')
| -rw-r--r-- | ihatemoney/web.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/ihatemoney/web.py b/ihatemoney/web.py index 18ce0c7..bbc98c4 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -37,10 +37,10 @@ from sqlalchemy_continuum import Operation from werkzeug.exceptions import NotFound from werkzeug.security import check_password_hash, generate_password_hash +from ihatemoney.currency_convertor import CurrencyConverter from ihatemoney.forms import ( AdminAuthenticationForm, AuthenticationForm, - EditProjectForm, InviteForm, MemberForm, PasswordReminder, @@ -48,6 +48,7 @@ from ihatemoney.forms import ( ResetPasswordForm, UploadForm, get_billform_for, + get_editprojectform_for, ) from ihatemoney.history import get_history, get_history_queries from ihatemoney.models import Bill, LoggingMode, Person, Project, db @@ -376,7 +377,7 @@ def reset_password(): @main.route("/<project_id>/edit", methods=["GET", "POST"]) def edit_project(): - edit_form = EditProjectForm() + edit_form = get_editprojectform_for(g.project) import_form = UploadForm() # Import form if import_form.validate_on_submit(): @@ -391,6 +392,18 @@ def edit_project(): # Edit form if edit_form.validate_on_submit(): project = edit_form.update(g.project) + # Update converted currency + if project.default_currency != CurrencyConverter.default: + for bill in project.get_bills(): + + if bill.original_currency == CurrencyConverter.default: + bill.original_currency = project.default_currency + + bill.converted_amount = CurrencyConverter().exchange_currency( + bill.amount, bill.original_currency, project.default_currency + ) + db.session.add(bill) + db.session.add(project) db.session.commit() @@ -478,6 +491,7 @@ def import_project(file, project): form.date = parse(b["date"]) form.payer = id_dict[b["payer_name"]] form.payed_for = owers_id + form.original_currency = b.get("original_currency") db.session.add(form.fake_form(bill, project)) @@ -543,6 +557,7 @@ def demo(): name="demonstration", password=generate_password_hash("demo"), contact_email="demo@notmyidea.org", + default_currency="EUR", ) db.session.add(project) db.session.commit() |
