From 535f9fce902287730d6786c44f77df2b9245a2ba Mon Sep 17 00:00:00 2001 From: Glandos Date: Thu, 1 Jul 2021 23:00:20 +0200 Subject: [PATCH] enforce multiple currency check in model On the same way that form validator does --- ihatemoney/models.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 80459182..31b1178b 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -274,7 +274,12 @@ class Project(db.Model): def switch_currency(self, new_currency): # Update converted 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: # Use old currency to flatten all amount before stripping