Fund every test account from the bank
This commit is contained in:
1 parent
fc480c7086
commit
bd5c59fd07
1 file changed
+25
-2
+25
-2
@@ -34,7 +34,15 @@ TRANSACTION_DEFAULTS = {
|
|||||||
RATE_2024 = 106037489
|
RATE_2024 = 106037489
|
||||||
|
|
||||||
|
|
||||||
def create_market(name, kind="exchange", taxable=1, custody_market_id=None):
|
def create_market(name, kind="exchange", taxable=1, custody_market_id=None,
|
||||||
|
kroner_ore=100000000):
|
||||||
|
"""Create an account, funded from the bank unless kroner_ore is 0.
|
||||||
|
|
||||||
|
No real account may go negative (docs/spec.md section 3.11), so a fixture that
|
||||||
|
pays kroner has to be funded first. The funding is dated before every other
|
||||||
|
row, so the replay sees it first and no figure moves: it is a transfer.
|
||||||
|
"""
|
||||||
|
bank = int(database.get_setting("bank_market_id"))
|
||||||
conn = database.connect()
|
conn = database.connect()
|
||||||
try:
|
try:
|
||||||
with conn:
|
with conn:
|
||||||
@@ -43,7 +51,22 @@ def create_market(name, kind="exchange", taxable=1, custody_market_id=None):
|
|||||||
" VALUES (?, ?, ?, ?)",
|
" VALUES (?, ?, ?, ?)",
|
||||||
(name, kind, taxable, custody_market_id),
|
(name, kind, taxable, custody_market_id),
|
||||||
)
|
)
|
||||||
return cursor.lastrowid
|
market_id = cursor.lastrowid
|
||||||
|
if kroner_ore:
|
||||||
|
group = "fund-%d" % market_id
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO transactions (date, type, market_id, leg_out_ore,"
|
||||||
|
" to_market_id, transfer_group, created_at, updated_at)"
|
||||||
|
" VALUES ('2000-01-01', 'transfer_out', ?, ?, ?, ?, 'x', 'x')",
|
||||||
|
(bank, kroner_ore, market_id, group),
|
||||||
|
)
|
||||||
|
conn.execute(
|
||||||
|
"INSERT INTO transactions (date, type, market_id, leg_in_ore,"
|
||||||
|
" to_market_id, transfer_group, generated, created_at, updated_at)"
|
||||||
|
" VALUES ('2000-01-01', 'transfer_in', ?, ?, ?, ?, 1, 'x', 'x')",
|
||||||
|
(market_id, kroner_ore, bank, group),
|
||||||
|
)
|
||||||
|
return market_id
|
||||||
finally:
|
finally:
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user