Create base currency on first call if none exists, fixing #1
This commit is contained in:
parent
0669e46a7a
commit
2feb3e637b
1 changed files with 8 additions and 2 deletions
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue