Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debt tracker #23

Merged
merged 33 commits into from
Nov 14, 2024
Merged

Debt tracker #23

merged 33 commits into from
Nov 14, 2024

Conversation

Sha-yol
Copy link
Contributor

@Sha-yol Sha-yol commented Nov 9, 2024

Partially solves #9 - adds the splitwise balance functionality.
When processing SW expenses, adds a withdrawal transaction from the paying account for the full amount payed, and adds a deposit to the SW balance account.
If processing an expense payed by others - only add a withdrawal transaction from the SW balance account.

Feature is implemented using strategy design pattern - a feature switch in the .env file determines whether to use the simple strategy or the SW balance strategy for transaction handling. main.py changes are minor, does not contain SW balance logic - almost all in the strategies/sw_balance.py file.

Waiting for comments and review :)

@Sha-yol
Copy link
Contributor Author

Sha-yol commented Nov 9, 2024

This was a long branch - when merging, can squash to make history neater.

Copy link
Owner

@adyanth adyanth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the continued contribution, this is great! A couple comments, nothing major. Looks good!

main.py Show resolved Hide resolved
main.py Outdated Show resolved Hide resolved
strategies/sw_balance.py Outdated Show resolved Hide resolved
strategies/sw_balance.py Outdated Show resolved Hide resolved
Handle it as one of the arguments to applyExpenseAmountToTransaction
Make a deposit to the SW balance account of amount "balance" when an expense entails people owe me money, instead of a transfer from the paying account to the SW balance, which doesn't make sense.
If type is "deposit", the asset account is the *destination*, not the *source*.
If I payed nothing on an expense, don't make a transaction from my real accounts, only from the balance account.
explicitly handle expenses where I paid nothing but I still owe something, and the edge case where an expense was recorded but I paid my whole share.
 Remove ability to pass ExpenseUser to get amount, pass amount explicitly. Rename method to clarify usage.
@adyanth
Copy link
Owner

adyanth commented Nov 12, 2024

Also, some tests seem to be failing. Mind taking a look? (A missing argument, and a decimal 0)

============================= test session starts ==============================
platform linux -- Python 3.13.0, pytest-8.3.3, pluggy-1.5.0
rootdir: /home/runner/work/splitwise-firefly-sync/splitwise-firefly-sync
plugins: cov-6.0.0
collected 20 items

tests/test_account_currency.py ...                                       [ 15%]
tests/test_main.py .........F...                                         [ 80%]
tests/test_strategies.py .F..                                            [100%]

=================================== FAILURES ===================================
________________________ test_getExpenseTransactionBody ________________________

mock_getAccountCurrencyCode = <MagicMock name='getAccountCurrencyCode' id='139855257463040'>
mock_expense = <MagicMock spec='Expense' id='139855257467408'>
mock_expense_user = <MagicMock spec='ExpenseUser' id='139855257462032'>

    @patch('main.getAccountCurrencyCode')
    def test_getExpenseTransactionBody(mock_getAccountCurrencyCode, mock_expense, mock_expense_user):
        getExpenseTransactionBody = load_main().getExpenseTransactionBody
        mock_getAccountCurrencyCode.return_value = "USD"
        result = getExpenseTransactionBody(mock_expense, mock_expense_user, ["Dest", "Category", "Desc", "Amex"])
    
        assert result["source_name"] == "Amex"
        assert result["destination_name"] == "Dest"
        assert result["category_name"] == "Category"
>       assert result["amount"] == "10.00"
E       AssertionError: assert '10.0' == '10.00'
E         
E         - 10.00
E         ?     -
E         + 10.0

tests/test_main.py:139: AssertionError
----------------------------- Captured stdout call -----------------------------
Processing Category Expense Test Expense for USD 10.00 on 2023-09-10T12:00:00Z from Amex to Dest
___________________________ test_sw_balance_strategy ___________________________

    def test_sw_balance_strategy():
>       strategy = SWBalanceTransactionStrategy(mock_get_expense_transaction_body, "Splitwise Balance")
E       TypeError: SWBalanceTransactionStrategy.__init__() missing 1 required positional argument: 'apply_transaction_amount'

tests/test_strategies.py:47: TypeError
- generated xml file: /home/runner/work/splitwise-firefly-sync/splitwise-firefly-sync/pytest.xml -

---------- coverage: platform linux, python 3.13.0-final-0 -----------
Coverage XML written to file coverage.xml

=========================== short test summary info ============================
FAILED tests/test_main.py::test_getExpenseTransactionBody - AssertionError: assert '10.0' == '10.00'
  
  - 10.00
  ?     -
  + 10.0
FAILED tests/test_strategies.py::test_sw_balance_strategy - TypeError: SWBalanceTransactionStrategy.__init__() missing 1 required positional argument: 'apply_transaction_amount'
========================= 2 failed, 18 passed in 0.70s =========================

@Sha-yol
Copy link
Contributor Author

Sha-yol commented Nov 13, 2024

I'm not why the automatic tests failed, but they passed on my machine after the latest commits.

@adyanth
Copy link
Owner

adyanth commented Nov 13, 2024

The tests are good now, the pipeline fails due to permissions, but if you open it, it does show the test results (not sure if you would have permissions for that too).

@Sha-yol
Copy link
Contributor Author

Sha-yol commented Nov 13, 2024 via email

@adyanth adyanth merged commit 902951e into adyanth:main Nov 14, 2024
0 of 2 checks passed
@Sha-yol Sha-yol deleted the debt-tracker branch November 19, 2024 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants