Skip to content

Commit

Permalink
added approved and cleared as adjustable values
Browse files Browse the repository at this point in the history
  • Loading branch information
dnbasta committed Mar 27, 2024
1 parent 641c168 commit 0d9703e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 7 deletions.
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion tests/test_modifiedtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion tests/test_originaltransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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


Expand Down
5 changes: 4 additions & 1 deletion tests/test_transationmodifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,6 +29,7 @@ def mock_subtransaction():
('payee', 'xxx'),
('category', 'xxx'),
('flag_color', 'brown'),
('cleared', 'xxx'),
('subtransactions', ['xxx', 'xxx']),
('transaction_date', 'xxx')
])
Expand Down
12 changes: 10 additions & 2 deletions ynabtransactionadjuster/models/modifiedtransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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')
Expand Down
8 changes: 7 additions & 1 deletion ynabtransactionadjuster/models/originaltransaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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':
Expand Down Expand Up @@ -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)
6 changes: 6 additions & 0 deletions ynabtransactionadjuster/models/transactionmodifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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')
Expand Down

0 comments on commit 0d9703e

Please sign in to comment.