Hello,

I would like to create a balance assertion

YYYY-MM-DD balance Account  Amount

program,atically: 
https://aumayr.github.io/beancount-docs-static/api_reference/beancount.core.html#beancount.core.data.Balance

The parameter description in the API docs is only "Alias for field X". The 
source code reveals some more information:

# Attributes:
#   meta: See above.
#   date: See above.
#   account: A string, the account whose balance to check at the given date.
#   amount: An Amount, the number of units of the given currency you're
#     expecting 'account' to have at this date.
#   diff_amount: None if the balance check succeeds. This value is set to
#     an Amount instance if the balance fails, the amount of the difference.
#   tolerance: A Decimal object, the amount of tolerance to use in the
#     verification.
Balance = new_directive('Balance', [
    ('account', Account),
    ('amount', Amount),
    ('tolerance', Optional[Decimal]),
    ('diff_amount', Optional[Amount])])


Just omitting the optional arguments doesn't work and gives a TypeError.

Using this piece of code:

value = desc.split(" ")[-1]  # value = "1.522,43H"
sign = 1 if value[-1] == "H" else -1
units = sign * amount.Amount(D(value[:-1].replace(".", "").replace(",", 
".")), "EUR")
print(units)
txn = data.Balance(meta,
                   datetime.datetime.strptime(row["Datum/Zeit"], "%d.%m.%Y 
%H:%M").date(),
                   account = self.file_account(),
                   amount = units,
                   tolerance = D(0), diff_amount = amount
                )

gives:

(Decimal('12415.79'), 'EUR')

Traceback (most recent call last):
  File "/usr/bin/bean-extract", line 4, in <module>
    from beancount.ingest.extract import main; main()
  File "/usr/lib/python3.7/site-packages/beancount/ingest/extract.py", line 
257, in main
    return scripts_utils.trampoline_to_ingest(sys.modules[__name__])
  File 
"/usr/lib/python3.7/site-packages/beancount/ingest/scripts_utils.py", line 
174, in trampoline_to_ingest
    return run_import_script_and_ingest(parser)
  File 
"/usr/lib/python3.7/site-packages/beancount/ingest/scripts_utils.py", line 
224, in run_import_script_and_ingest
    return ingest(importers_list)
  File 
"/usr/lib/python3.7/site-packages/beancount/ingest/scripts_utils.py", line 
116, in ingest
    detect_duplicates_func=detect_duplicates_func)
  File "/usr/lib/python3.7/site-packages/beancount/ingest/extract.py", line 
252, in run
    detect_duplicates_func=detect_duplicates_func)
  File "/usr/lib/python3.7/site-packages/beancount/ingest/extract.py", line 
218, in extract
    print_extracted_entries(new_entries, output)
  File "/usr/lib/python3.7/site-packages/beancount/ingest/extract.py", line 
140, in print_extracted_entries
    entry_string = printer.format_entry(entry)
  File "/usr/lib/python3.7/site-packages/beancount/parser/printer.py", line 
339, in format_entry
    return EntryPrinter(dcontext, render_weights)(entry)
  File "/usr/lib/python3.7/site-packages/beancount/parser/printer.py", line 
117, in __call__
    method(obj, oss)
  File "/usr/lib/python3.7/site-packages/beancount/parser/printer.py", line 
254, in Balance
    amount=entry.amount.to_string(self.dformat),
AttributeError: 'tuple' object has no attribute 'to_string'

when attached to the list of statements that is returned from the extract() 
function.

Also, I am obviosuly still having some problems crasping beancounts type 
system, esp. with optional parameters, like creating a transaction:

  txn = data.Transaction(meta, date, "*", payee, desc, set(), set(), [
                        data.Posting("Assets:Checking", units, None, None, 
None, None),
                        data.Posting("Expenses:Unknown", None, None, None, 
None, None)])

took me some time to find out, that I need to pass set() to some empty 
arguments, None to others.

My questions:

* How can I programmatically create a balance assertion?

* How do the parameters diff_amount and tolerance reflect in the produced 
statements? The balance statement does not seem to have these fields.

* What is the meaning of the diff_amount?

* And finally: Is there something I don't understand regarding beancount's 
API? So far, it feels a bit unpythonic.


Thanks a lot,
Florian

-- 
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/f2123ceb-8a2a-40ca-ae56-f7b0527e413b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to