Skip to content

Commit

Permalink
Simplifying tests as it was a bit flaky between postgres and mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
adamcharnock committed Jul 28, 2024
1 parent ef8cf08 commit e75321d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
19 changes: 17 additions & 2 deletions hordak/migrations/0052_amount_to_debit_credit_sql.mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ END;

-- ----

CREATE OR REPLACE FUNCTION get_balance(account_id BIGINT, as_of DATE)
CREATE OR REPLACE FUNCTION get_balance(account_id BIGINT, as_of DATE, as_of_leg_id BIGINT)
RETURNS JSON
BEGIN
DECLARE account_lft INT;
Expand All @@ -244,6 +244,13 @@ BEGIN
DECLARE account_type TEXT;
DECLARE account_sign INT;

IF as_of IS NULL AND as_of_leg_id IS NOT NULL THEN
SET @msg= 'get_balance_table(): You must specify the as_of parameter if also specifying the as_of_leg_id parameter';
SIGNAL SQLSTATE '23000' SET
MYSQL_ERRNO = 1048,
MESSAGE_TEXT = @msg;
end if;

-- Fetch the account's hierarchical information
SELECT lft, rght, tree_id, type INTO account_lft, account_rght, account_tree_id, account_type
FROM hordak_account
Expand All @@ -269,7 +276,15 @@ BEGIN
FROM hordak_account A2
JOIN hordak_leg L ON L.account_id = A2.id
JOIN hordak_transaction T ON L.transaction_id = T.id
WHERE A2.lft >= account_lft AND A2.rght <= account_rght AND A2.tree_id = account_tree_id AND T.date <= as_of
WHERE
A2.lft >= account_lft
AND A2.rght <= account_rght
AND A2.tree_id = account_tree_id
AND (
T.date < as_of
OR
T.date = as_of AND (CASE WHEN as_of_leg_id IS NOT NULL THEN L.id <= as_of_leg_id ELSE TRUE END)
)
GROUP BY L.currency
) AS sub
);
Expand Down
11 changes: 6 additions & 5 deletions hordak/tests/admin/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,13 @@ def test_account_list(self):
f'<a href="/admin/hordak/account/{self.bank_account.id}/change/">Bank account</a>',
html=True,
)
self.assertContains(res, '<td class="field-balance">10.000000</td>', html=True)

self.assertContains(res, '<td class="field-balance">0</td>', html=True)
self.assertContains(res, '<td class="field-type_">-</td>', html=True)
self.assertContains(res, '<td class="field-type_">Income</td>', html=True)
self.assertContains(res, '<td class="field-type_">Asset</td>', html=True)
qs = res.context_data["cl"].queryset
self.assertEqual(qs.count(), 4)
self.assertEqual(qs[0].balance, 0)
self.assertEqual(qs[1].balance, 0)
self.assertEqual(qs[2].balance, 10)
self.assertEqual(qs[3].balance, 10)

def test_account_search_query(self):
"""Test that search query works"""
Expand Down

0 comments on commit e75321d

Please sign in to comment.