diff --git a/oldabe/money_in/__init__.py b/oldabe/money_in/__init__.py index 03c7acc..0aa1c89 100755 --- a/oldabe/money_in/__init__.py +++ b/oldabe/money_in/__init__.py @@ -137,6 +137,10 @@ def distribute_payment( return processed_debts, debt_payments, transactions, advances +# TODO: the payments within a commit are not ordered. +# It may be better to sort them chronologically, so that +# earlier payments are reflected in attributions before +# later payments are processed. def process_payments(instruments, attributions): """ Process new payments by paying out instruments and then, from the amount diff --git a/tests/integration/old_abe_test.py b/tests/integration/old_abe_test.py index 8626ec0..8df58ef 100644 --- a/tests/integration/old_abe_test.py +++ b/tests/integration/old_abe_test.py @@ -192,6 +192,66 @@ def test_compiled_outstanding_balances(self, mock_git_rev, abe_fs): ) in message +class TestMultiplePayments: + + # TODO: implement me + @time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False) + @patch('oldabe.models.default_commit_hash', return_value='abcd123') + def test_generates_transactions(self, mock_git_rev, abe_fs): + pass + + @time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False) + @patch('oldabe.models.default_commit_hash', return_value='abcd123') + def test_dilutes_attributions(self, mock_git_rev, abe_fs): + with localcontext() as context: + context.prec = 2 + amount = 10000 + abe_fs.create_file( + "./abe/payments/1.txt", + contents=f"sam,036eaf6,{amount},1987-06-30 06:25:00", + ) + abe_fs.create_file( + "./abe/payments/2.txt", + contents=f"sam,036eaf6,{amount},1987-06-30 06:24:00", + ) + process_payments_and_record_updates() + with open('./abe/attributions.txt') as f: + assert f.read() == ( + "sid,42\n" "jair,26\n" "ariana,17\n" "sam,16\n" + ) + + # TODO: why do sam and sri not get into attributions when the amount + # is 1000? For higher amounts like 10000 it seems OK + # TODO: add a test to check that, even though both sam and sri get + # attributed equally, sam gets paid from sri's payment, + # but sri doesn't get paid from sam's, assuming sam is first + @time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False) + @patch('oldabe.models.default_commit_hash', return_value='abcd123') + def test_equal_payment_results_in_equal_share(self, mock_git_rev, abe_fs): + with localcontext() as context: + context.prec = 2 + amount = 10000 + abe_fs.create_file( + "./abe/payments/1.txt", + contents=f"sam,036eaf6,{amount},1987-06-30 06:25:00", + ) + abe_fs.create_file( + "./abe/payments/2.txt", + contents=f"sri,b36eaf6,{amount},1987-06-30 06:24:00", + ) + process_payments_and_record_updates() + with open('./abe/attributions.txt') as f: + assert f.read() == ( + "sid,42\n" "jair,26\n" "ariana,17\n" "sam,7.8\n" "sri,7.8\n" + ) + + # TODO: implement me + @time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False) + @patch('oldabe.models.default_commit_hash', return_value='abcd123') + def test_compiled_outstanding_balances(self, mock_git_rev, abe_fs): + pass + + class TestUnpayableContributor: def _call(self, abe_fs):