Create base currency on first call if none exists, fixing #1

This commit is contained in:
Kumi 2021-11-12 19:47:49 +01:00
parent 0669e46a7a
commit 2feb3e637b

View file

@ -17,7 +17,13 @@ class Currency(Model):
@classmethod
def get_base(cls):
return cls.objects.get(base=True)
try:
return cls.objects.get(base=True)
except cls.DoesNotExist:
try:
return cls.objects.first()
except cls.DoesNotExist:
return cls.objects.create(name="Euro", code="EUR", symbol="", base=True)
def __str__(self):
return f"{self.name} ({self.code})"
@ -42,4 +48,4 @@ class TaxRule(Model):
reverse_charge = BooleanField(default=False)
def __str__(self):
return str(self.destination_country)
return str(self.destination_country)