Adding sequence number for transactions and fixtures as well
This commit is contained in:
36
api/app/transaction/fixtures.py
Normal file
36
api/app/transaction/fixtures.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import random
|
||||
from datetime import date, timedelta
|
||||
|
||||
from account.resource import AccountResource
|
||||
from transaction.models import TransactionCreate, Split
|
||||
from transaction.resource import TransactionResource
|
||||
|
||||
|
||||
def inject_fixtures(session):
|
||||
for f in fixtures_transaction:
|
||||
for i in range(f["count"]):
|
||||
data = prepare_dict(session, f, i)
|
||||
schema = TransactionCreate(**data)
|
||||
schema.splits.append(Split(**data))
|
||||
TransactionResource.create(session, schema)
|
||||
|
||||
def prepare_dict(session, entry, iteration):
|
||||
account = AccountResource.get_by_path(session, entry['account_path'])
|
||||
result = entry.copy()
|
||||
|
||||
result["account_id"] = account.id
|
||||
result["payee_id"] = None
|
||||
result["splits"] = []
|
||||
result["transaction_date"] = entry["start_date"] + timedelta(days=(iteration / 2))
|
||||
result["amount"] = ["10", "100", "1000"][random.Random().randint(0,2)]
|
||||
result["id"] = 0
|
||||
|
||||
return result
|
||||
|
||||
fixtures_transaction = [
|
||||
{
|
||||
"account_path": "/Accounts/Asset/Current Assets/Checking Account/",
|
||||
"start_date": date(1970, 1, 5),
|
||||
"count": 50
|
||||
},
|
||||
]
|
||||
Reference in New Issue
Block a user