From c0796c1ebf73899318949fde48079b264f707c96 Mon Sep 17 00:00:00 2001 From: Glandos Date: Sun, 4 Jul 2021 15:46:50 +0200 Subject: [PATCH] clearer code when switching to another currency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit the code has the same effect for the database, but should be clearer for reviewers ;) --- ihatemoney/models.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 31b1178b..75961104 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -289,14 +289,15 @@ class Project(db.Model): # Strip currency bill.amount = bill.converted_amount bill.original_currency = CurrencyConverter.no_currency + elif bill.original_currency == CurrencyConverter.no_currency: + # Bills that were created without currency will be set to the new currency + bill.original_currency = new_currency + bill.converted_amount = bill.amount else: - # Switch to new currency for everyone + # Convert amount for others, without touching original_currency bill.converted_amount = CurrencyConverter().exchange_currency( bill.amount, bill.original_currency, new_currency ) - # Add the currency for bills that were created without currency - if bill.original_currency == CurrencyConverter.no_currency: - bill.original_currency = new_currency db.session.add(bill) self.default_currency = new_currency db.session.add(self)