Beancount is primarily designed to read+process input files, which is 
different from what you're attempting (create+write). May I ask what your 
end goal is?

You can create and write, which is what the importers do. Look at 
extract.py, which will show you how to do this. The main problem above is, 
nowhere are you actually printing output to a file.

On Thursday, March 30, 2023 at 10:53:20 AM UTC-7 Morpheous wrote:

> I am using beancount 2.3.5 
> <https://github.com/beancount/beancount/tree/2.3.5> and I am trying to 
> write a proof of concept file that does the following:
>
>    1. Creates a simple chart of accounts
>    2. Posts sample transactions into ledgers using double entry
>
> This is my code:
> from datetime import datetime
> from decimal import Decimal as D 
> import beancount.core.data as data 
> line_number = 42 
>
> metadata = data.new_metadata(filename='./myfile.beancount', 
> lineno=line_number) 
>
> # define accounts 
> accounts = ["Assets:Bank", "Expenses:Groceries"] 
>
> # create postings 
> posting1 = data.Posting(accounts[0], data.Amount(D('1000'), 'USD'), None, 
> None, None, meta=metadata) 
> posting2 = data.Posting(accounts[1], data.Amount(D('200'), 'USD'), None, 
> None, None, meta=metadata) 
>
> # create transactions 
> transaction1 = data.Transaction( meta = metadata, date = datetime.strptime(
> "2022-03-29", '%Y-%m-%d'), flag = "*", payee = "Bob's Grocery Store", 
> narration = "Groceries for the week", tags = set(), links = set(), 
> postings = [posting1, posting2] )
>
>
> After I run the code, I expect to see a newly created file 
> myfile.beancount with the above transactions in it. However, no file is 
> generated.
>
> I suspect that I might have to mark the accounts as open first, but I 
> can't see anywhere in the documentation (or a function/method in the source 
> code) that provides a clean entrypoint to do that.
>
> How do I modify this code so that it creates the file and correctly posts 
> the transactions to the file?
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/5424e69f-3105-4ee1-beda-154c18c2c950n%40googlegroups.com.

Reply via email to