clearer code when switching to another currency

the code has the same effect for the database, but should be
clearer for reviewers ;)
This commit is contained in:
Glandos 2021-07-04 15:46:50 +02:00
parent 8ee59b3509
commit c0796c1ebf

View file

@ -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)