Looking to get feedback on the proper way to create new transactions 
through a Python script. I'm working on the beginnings of a paycheck parser 
and am starting by making myself some useful wrappers, but I don't want to 
reinvent the wheel unnecessarily. Here is my sample code for making a new 
transaction and printing it:

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))


There's some acrobatics required to make a new transaction, so the 
objective above was to simplify the process by providing defaults for the 
mostly optional parameters. Also, I hid the units magic when it comes to 
making new postings.

Anyways, I've spent some time combing through the source code, but I 
haven't given an extensive review of every file. With that being said, I 
just want to make sure I'm not reinventing helper functions that already 
exist. Any pointers?

-- 
You received this message because you are subscribed to the Google Groups 
"Beancount" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/0411ccfa-d400-4c96-97e9-0a7fb68ae3fa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to