From 90e247c5225f63f761eef2d4948b8ef4d09294ac Mon Sep 17 00:00:00 2001 From: harshajv7981 <87539405+harshajv7981@users.noreply.github.com> Date: Mon, 26 Oct 2026 10:41:03 +0530 Subject: [PATCH] Fix Amount __sub__ and __eq__ referencing removed currency_type Commit 48562de renamed the attribute to ccy_name but left these two references behind, so subtracting or comparing Amounts raised AttributeError. --- financepy/utils/amount.py | 4 ++-- tests/unit/test_FinAmount.py | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/financepy/utils/amount.py b/financepy/utils/amount.py index d3afc0ee..42af7e81 100644 --- a/financepy/utils/amount.py +++ b/financepy/utils/amount.py @@ -64,7 +64,7 @@ def __sub__(self, other): return Amount( self.amount - other.amount, - self.currency_type, + self.ccy_name, ) def __mul__(self, scalar): @@ -97,7 +97,7 @@ def __eq__(self, other): return False return ( - self.currency_type == other.currency_type + self.ccy_name == other.ccy_name and self.amount == other.amount ) diff --git a/tests/unit/test_FinAmount.py b/tests/unit/test_FinAmount.py index b6ec0f92..102a8e37 100644 --- a/tests/unit/test_FinAmount.py +++ b/tests/unit/test_FinAmount.py @@ -9,3 +9,12 @@ def test_amount(): amt = Amount(101000.232, "CAD") assert repr(amt) == "CAD 101,000.23" + + +def test_amount_sub_and_eq(): + + diff = Amount(100.0, "CAD") - Amount(40.0, "CAD") + assert diff.amount == 60.0 + assert diff.ccy_name == "CAD" + assert Amount(1.0, "CAD") == Amount(1.0, "CAD") + assert Amount(1.0, "CAD") != Amount(1.0, "USD")