From 0d9703e1dc49d895726d5879dd7980c274db8040 Mon Sep 17 00:00:00 2001 From: dnbasta Date: Wed, 27 Mar 2024 07:07:28 +0100 Subject: [PATCH] added approved and cleared as adjustable values --- tests/conftest.py | 4 +++- tests/test_modifiedtransaction.py | 6 +++++- tests/test_originaltransaction.py | 5 ++++- tests/test_transationmodifier.py | 5 ++++- .../models/modifiedtransaction.py | 12 ++++++++++-- .../models/originaltransaction.py | 8 +++++++- .../models/transactionmodifier.py | 6 ++++++ 7 files changed, 39 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 35e570f..cee06ba 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -33,7 +33,9 @@ def mock_original_transaction(request): amount=1000, import_payee_name='ipn', import_payee_name_original='ipno', - transaction_date=date(2024, 1, 1)) + transaction_date=date(2024, 1, 1), + approved=False, + cleared='uncleared') @pytest.fixture diff --git a/tests/test_modifiedtransaction.py b/tests/test_modifiedtransaction.py index e041b59..ccc4527 100644 --- a/tests/test_modifiedtransaction.py +++ b/tests/test_modifiedtransaction.py @@ -11,7 +11,9 @@ ('transaction_date', date(2024, 1, 2)), ('category', Category(id='c_id1', name='c_name1')), ('payee', Payee(id='p_id1', name='p_name1', transfer_account_id='t_id1')), - ('flag_color', 'blue')]) + ('flag_color', 'blue'), + ('approved', True), + ('cleared', 'cleared')]) def test_is_changed_true(test_attribute, test_input, mock_original_transaction): # Arrange mock_modifier = TransactionModifier.from_original_transaction(mock_original_transaction) @@ -64,6 +66,8 @@ def test_as_dict(mock_original_transaction, mock_subtransaction): assert len(d['subtransactions']) == 2 assert isinstance(d['subtransactions'][0], dict) assert d['date'] == datetime.strftime(mock_modifier.transaction_date, '%Y-%m-%d') + assert d['approved'] == mock_modifier.approved + assert d['cleared'] == mock_modifier.cleared def test_as_dict_none_values(mock_original_transaction): diff --git a/tests/test_originaltransaction.py b/tests/test_originaltransaction.py index 6e5a565..ff84922 100644 --- a/tests/test_originaltransaction.py +++ b/tests/test_originaltransaction.py @@ -9,7 +9,8 @@ def mock_transaction_dict(): return dict(id='id', amount=1000, date='2024-01-01', category_name='category', category_id='categoryid', payee_name='payee', payee_id='payeeid', flag_color=None, memo=None, subtransactions=[], - import_payee_name_original=None, import_payee_name=None, transfer_account_id=None) + import_payee_name_original=None, import_payee_name=None, transfer_account_id=None, + approved=False, cleared='uncleared') def test_from_dict(mock_transaction_dict): @@ -23,6 +24,8 @@ def test_from_dict(mock_transaction_dict): assert o.memo == mock_transaction_dict['memo'] assert o.import_payee_name_original == mock_transaction_dict['import_payee_name_original'] assert o.import_payee_name == mock_transaction_dict['import_payee_name'] + assert o.approved == mock_transaction_dict['approved'] + assert o.cleared == mock_transaction_dict['cleared'] assert not o.subtransactions diff --git a/tests/test_transationmodifier.py b/tests/test_transationmodifier.py index 7ba8e8d..f176d75 100644 --- a/tests/test_transationmodifier.py +++ b/tests/test_transationmodifier.py @@ -13,7 +13,9 @@ def mock_modifier(request): category=Category(name='cname', id='cid'), flag_color='red', subtransactions=[], - transaction_date=date(2024, 1, 1)) + transaction_date=date(2024, 1, 1), + cleared='uncleared', + approved=False) @pytest.fixture @@ -27,6 +29,7 @@ def mock_subtransaction(): ('payee', 'xxx'), ('category', 'xxx'), ('flag_color', 'brown'), + ('cleared', 'xxx'), ('subtransactions', ['xxx', 'xxx']), ('transaction_date', 'xxx') ]) diff --git a/ynabtransactionadjuster/models/modifiedtransaction.py b/ynabtransactionadjuster/models/modifiedtransaction.py index 7cc06e1..d4a731f 100644 --- a/ynabtransactionadjuster/models/modifiedtransaction.py +++ b/ynabtransactionadjuster/models/modifiedtransaction.py @@ -24,7 +24,9 @@ def as_dict(self) -> dict: t_dict = dict(id=self.original_transaction.id, payee_name=self.transaction_modifier.payee.name, payee_id=self.transaction_modifier.payee.id, - date=datetime.strftime(self.transaction_modifier.transaction_date, '%Y-%m-%d')) + date=datetime.strftime(self.transaction_modifier.transaction_date, '%Y-%m-%d'), + approved=self.transaction_modifier.approved, + cleared=self.transaction_modifier.cleared) if len(self.transaction_modifier.subtransactions) > 0: t_dict['subtransactions'] = [s.as_dict() for s in self.transaction_modifier.subtransactions] if self.transaction_modifier.category: @@ -58,7 +60,13 @@ def changed_attributes(self) -> dict: changed=self.transaction_modifier.flag_color) if len(self.transaction_modifier.subtransactions) > 0: changed_attributes['subtransactions'] = dict(original=[], - changed=self.transaction_modifier.subtransactions) + changed=self.transaction_modifier.subtransactions) + if self.transaction_modifier.approved != self.original_transaction.approved: + changed_attributes['approved'] = dict(original=self.original_transaction.approved, + changed=self.transaction_modifier.approved) + if self.transaction_modifier.cleared != self.original_transaction.cleared: + changed_attributes['cleared'] = dict(original=self.original_transaction.cleared, + changed=self.transaction_modifier.cleared) return changed_attributes @model_validator(mode='after') diff --git a/ynabtransactionadjuster/models/originaltransaction.py b/ynabtransactionadjuster/models/originaltransaction.py index 896a0ea..9ecae62 100644 --- a/ynabtransactionadjuster/models/originaltransaction.py +++ b/ynabtransactionadjuster/models/originaltransaction.py @@ -20,6 +20,8 @@ class OriginalTransaction: :ivar flag_color: The flag color of the original transaction :ivar import_payee_name: The payee as recorded by YNAB on import :ivar import_payee_name_original: The original payee or memo as recorded by the bank + :ivar approved: approval status of the original transaction + :ivar cleared: clearance state of the original transaction """ id: str transaction_date: date @@ -31,6 +33,8 @@ class OriginalTransaction: import_payee_name_original: Optional[str] import_payee_name: Optional[str] subtransactions: Tuple[OriginalSubTransaction, ...] + cleared: Literal['uncleared', 'cleared', 'reconciled'] + approved: bool @classmethod def from_dict(cls, t_dict: dict) -> 'OriginalTransaction': @@ -58,7 +62,9 @@ def build_subtransaction(s_dict: dict) -> OriginalSubTransaction: flag_color=t_dict['flag_color'], payee=build_payee(t_dict), subtransactions=tuple([build_subtransaction(st) for st in t_dict['subtransactions']]), - amount=t_dict['amount']) + amount=t_dict['amount'], + approved=t_dict['approved'], + cleared=t_dict['cleared']) def as_dict(self) -> dict: return asdict(self) diff --git a/ynabtransactionadjuster/models/transactionmodifier.py b/ynabtransactionadjuster/models/transactionmodifier.py index f490efc..55f9061 100644 --- a/ynabtransactionadjuster/models/transactionmodifier.py +++ b/ynabtransactionadjuster/models/transactionmodifier.py @@ -17,6 +17,8 @@ class TransactionModifier(BaseModel): :ivar payee: The payee of the transaction :ivar flag_color: The flag color of the transaction :ivar subtransactions: The subtransactions of the transaction + :ivar cleared: Clearance status + :ivar approved: Approval status of the transaction """ transaction_date: date @@ -25,6 +27,8 @@ class TransactionModifier(BaseModel): payee: Payee flag_color: Optional[Literal['red', 'green', 'blue', 'orange', 'purple', 'yellow']] subtransactions: List[SubTransaction] + approved: bool + cleared: Literal['uncleared', 'cleared', 'reconciled'] @classmethod def from_original_transaction(cls, original_transaction: OriginalTransaction): @@ -33,6 +37,8 @@ def from_original_transaction(cls, original_transaction: OriginalTransaction): payee=original_transaction.payee, memo=original_transaction.memo, flag_color=original_transaction.flag_color, + approved=original_transaction.approved, + cleared=original_transaction.cleared, subtransactions=[]) @model_validator(mode='after')