mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-05-06 05:01:48 +02:00
parent
27d95f2d01
commit
219f308e8c
1 changed files with 20 additions and 7 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue