Coverage for django_napse/core/models/transactions/transaction.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-12 13:49 +0000

1from django.db import models 

2 

3from django_napse.core.models.transactions.managers import TransactionManager 

4 

5 

6class Transaction(models.Model): 

7 from_wallet = models.ForeignKey("Wallet", on_delete=models.CASCADE, related_name="transactions_from") 

8 to_wallet = models.ForeignKey("Wallet", on_delete=models.CASCADE, related_name="transactions_to") 

9 amount = models.FloatField() 

10 ticker = models.CharField(max_length=10) 

11 transaction_type = models.CharField(max_length=20, default="TRANSFER") 

12 created_at = models.DateTimeField(auto_now_add=True) 

13 

14 objects = TransactionManager() 

15 

16 def __str__(self): 

17 return f"TRANSACTION: {self.from_wallet.pk} -> {self.to_wallet.pk} ({self.amount=} - {self.ticker=})" 

18 

19 def info(self, verbose=True, beacon=""): 

20 string = "" 

21 string += f"{beacon}Transaction {self.pk=}\n" 

22 string += f"{beacon}Args:\n" 

23 string += f"{beacon}\t{self.amount=}\n" 

24 string += f"{beacon}\t{self.ticker=}\n" 

25 string += f"{beacon}\t{self.transaction_type=}\n" 

26 string += f"{beacon}From Wallet:\n" 

27 wall_str = self.from_wallet.info(verbose=False, beacon=beacon + "\t") 

28 string += f"{wall_str}\n" 

29 string += f"{beacon}To Wallet:\n" 

30 wall_str = self.to_wallet.info(verbose=False, beacon=beacon + "\t") 

31 string += f"{wall_str}\n" 

32 if verbose: # pragma: no cover 

33 print(string) 

34 return string