import beancount.core.amount as amount
from beancount.core.data import Posting, Transaction
from beancount.parser import printer
from datetime import date
def new_posting(account, units=None, cost=None, price=None, flag=None, meta=None):
if units:
units = amount.from_string(units)
return Posting(account=account,
units=units,
cost=cost,
price=price,
flag=flag,
meta=meta)
def new_transaction(date, flag, postings, payee='', narration='', tags=None, links=None, meta=None):
return Transaction(date=date,
flag=flag,
postings=postings,
payee=payee,
narration=narration,
tags=tags,
links=links,
meta=meta)
postings = []
postings.append(new_posting('Assets:Some:Account', '100.00 USD'))
postings.append(new_posting('Expenses:Some:Account'))
trans = new_transaction(date.today(), '*', postings, narration='Test transaction')
print(printer.format_entry(trans))