On 16/02/24 22:51, Mason H wrote:
Hello,

I've recently been trying to write an importer script and was trying to use a Custom directive. There isn't a lot of documentation on this, and I haven't been able to figure out what the problem is from the source, and was wondering if anyone here had any ideas. I'm not sure if I'm using beancount.core.data.Custom wrong or if you're supposed to use a different object entirely.

Issue occurs when there is a beancount.core.data.Custom object in the list returned by the extract() function

[...]

ret.append(data.Custom(meta, date, "example", ["value1", "value2", "value3"]))

The fourth field in a beancount.core.data.Custom() object is a list of beancount.parser.grammar.ValueType() instances. ValueType() instances are initialized with a value and a data type (a Python class). Therefore, your code should read something like:

ret.append(data.Custom(
    meta, date, "example", [
        grammar.ValueType("value1", str),
        grammar.ValueType("value2", str),
        grammar.ValueType("value3", str),
    ])
)

An easy way to figure out this kind of things is to run the parser on the Beancount format representation of the directive you want to obtain:

from beancount.parser import parser
entries, errors, options = parser.parse_string(
    '''2024-02-17 custom "example" "value1" "value2" "value3"'''
)
print(entries)

Cheers,
Dan

--
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/c1dd361c-3b5c-4f2a-8289-dc4692930899%40grinta.net.

Reply via email to