Coverage for django_napse/core/models/wallets/currency.py: 95%
22 statements
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
« prev ^ index » next coverage.py v7.4.3, created at 2024-03-12 13:49 +0000
1from django.db import models
4class Currency(models.Model):
5 wallet = models.ForeignKey("Wallet", on_delete=models.CASCADE, related_name="currencies")
6 mbp = models.FloatField()
7 ticker = models.CharField(max_length=10)
8 amount = models.FloatField(default=0)
10 class Meta:
11 unique_together = ("wallet", "ticker")
13 def __str__(self): # pragma: no cover
14 return f"CURRENCY {self.pk}"
16 def info(self, verbose=True, beacon=""):
17 string = ""
18 string += f"{beacon}Currency ({self.pk=}):\n"
19 string += f"{beacon}Args:\n"
20 string += f"{beacon}\t{self.wallet=}\n"
21 string += f"{beacon}\t{self.mbp=}\n"
22 string += f"{beacon}\t{self.ticker=}\n"
23 string += f"{beacon}\t{self.amount=}\n"
25 if verbose: # pragma: no cover
26 print(string)
27 return string
29 @property
30 def testing(self):
31 return self.wallet.testing
33 def copy(self, owner):
34 return Currency.objects.create(
35 wallet=owner,
36 mbp=self.mbp,
37 ticker=self.ticker,
38 amount=self.amount,
39 )