diff --git a/ihatemoney/web.py b/ihatemoney/web.py index baacff47..576d6e10 100644 --- a/ihatemoney/web.py +++ b/ihatemoney/web.py @@ -414,17 +414,30 @@ def edit_project(): # Edit form if edit_form.validate_on_submit(): + old_currency = g.project.default_currency project = edit_form.update(g.project) # Update converted currency - if project.default_currency != CurrencyConverter.no_currency: + if project.default_currency != old_currency: for bill in project.get_bills(): + if bill.original_currency == project.default_currency: + continue - if bill.original_currency == CurrencyConverter.no_currency: - bill.original_currency = project.default_currency - - bill.converted_amount = CurrencyConverter().exchange_currency( - bill.amount, bill.original_currency, project.default_currency - ) + if project.default_currency == CurrencyConverter.no_currency: + # Use old currency before stripping + bill.converted_amount = CurrencyConverter().exchange_currency( + bill.amount, bill.original_currency, old_currency + ) + # Strip currency + bill.amount = bill.converted_amount + bill.original_currency = CurrencyConverter.no_currency + else: + # Switch to new currency for everyone + bill.converted_amount = CurrencyConverter().exchange_currency( + bill.amount, bill.original_currency, project.default_currency + ) + # Add the currency for previously un-currency-ied + if bill.original_currency == CurrencyConverter.no_currency: + bill.original_currency = project.default_currency db.session.add(bill) db.session.add(project)