From 9627c4426614d5ad9d57f56e93ba5c53e10ed387 Mon Sep 17 00:00:00 2001 From: uvok Date: Thu, 17 Apr 2025 17:48:50 +0200 Subject: Add refid to tax --- test_trade.py | 4 ++-- trade.py | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/test_trade.py b/test_trade.py index ab853d1..8cbf0f4 100644 --- a/test_trade.py +++ b/test_trade.py @@ -9,7 +9,7 @@ class TestTrade(unittest.TestCase): """ Set up a Trade instance for testing. """ - self.trade = Trade(amount=Decimal(10.0), total_cost=Decimal(100.0), date="2025-04-14") + self.trade = Trade(amount=Decimal(10.0), total_cost=Decimal(100.0), date="2025-04-14", refid="abcd1234") def test_initialization(self): """ @@ -67,7 +67,7 @@ class TestTrade(unittest.TestCase): """ Test the __repr__ method for correct string representation. """ - expected_repr = "Trade(amount=10.00, price_per_coin=10.00, total_cost=100.00, date=2025-04-14)" + expected_repr = "Trade(amount=10.00, price_per_coin=10.00, total_cost=100.00, date=2025-04-14, refid=abcd1234)" self.assertEqual(repr(self.trade), expected_repr) diff --git a/trade.py b/trade.py index a07efe7..796f824 100644 --- a/trade.py +++ b/trade.py @@ -13,7 +13,9 @@ class Trade: Provides methods to modify the trade and access various attributes. """ - def __init__(self, amount: Decimal, total_cost: Decimal, date: str) -> None: + def __init__( + self, amount: Decimal, total_cost: Decimal, date: str, refid: str | None = None + ) -> None: """ Initialize a new Trade instance. @@ -29,6 +31,7 @@ class Trade: self.__amount: Decimal = Decimal(amount) self.__total_cost: Decimal = Decimal(total_cost) self.__date: str = date + self.__refid: str | None = refid def remove_coins( self, @@ -114,4 +117,5 @@ class Trade: Returns: str: A formatted string displaying the trade details. """ - return f"Trade(amount={self.amount:.2f}, price_per_coin={self.price_per_coin:.2f}, total_cost={self.total_cost:.2f}, date={self.date})" + rid = self.__refid or "" + return f"Trade(amount={self.amount:.2f}, price_per_coin={self.price_per_coin:.2f}, total_cost={self.total_cost:.2f}, date={self.date}, refid={rid})" -- cgit v1.2.3