[Python] beancount not creating double entry transactions and postings to file

Discussão em 'Python' iniciado por Stack, Fevereiro 26, 2025.

  1. Stack

    Stack Membro Participativo

    I am using beancount 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?

    Continue reading...

Compartilhe esta Página