enforce multiple currency check in model

On the same way that form validator does
This commit is contained in:
Glandos 2021-07-01 23:00:20 +02:00
parent 867e84ae91
commit 535f9fce90

View file

@ -274,7 +274,12 @@ class Project(db.Model):
def switch_currency(self, new_currency): def switch_currency(self, new_currency):
# Update converted currency # Update converted currency
if new_currency != self.default_currency: if new_currency != self.default_currency:
for bill in self.get_bills(): if (
new_currency == CurrencyConverter.no_currency
and self.has_multiple_currencies()
):
raise ValueError(f"Can't unset currency of project {self.id}")
for bill in self.get_bills_unordered():
if new_currency == CurrencyConverter.no_currency: if new_currency == CurrencyConverter.no_currency:
# Use old currency to flatten all amount before stripping # Use old currency to flatten all amount before stripping