On Tue, Jul 18, 2023 at 9:57 AM Daniele Nicolodi <dani...@grinta.net> wrote:

> On 18/07/23 04:47, Eric Altendorf wrote:
> > I've got my first importer running, mostly works, but the cost I'm
> > providing doesn't seem to be making it all the way through.  A debug
> > print shows this as the transaction I'm returning:
> >
> > Transaction(meta={'filename': '/home/...csv', 'lineno': 1},
> > date=datetime.date(2018, 1, 1), flag='*', payee=None, narration='Bought
> > 2.0 ABC for $204.00 USD', tags=frozenset(), links={None},
> > postings=[Posting(account='Assets:MyInstitution:ABC', units=2.0 ABC,
> > *cost=Cost(number='102.00', currency='USD', date=None, label=None)*,
> > price=102.00 USD, flag=None, meta=None),
> > Posting(account='Assets:MyInstitution:USD', units=-204.00 USD,
> > cost=None, price=None, flag=None, meta=None)])
> >
> > But the final transaction printed by the importer has no cost:
> >
> > 2018-01-01 * "Bought 2.0 ABC for $204.00 USD" ^None
> >    Assets:MyInstitution:ABC          2.0 ABC*{} *@ 102.00 USD
> >    Assets:MyInstitution:USD      -204.00 USD
> >
> > Any ideas?
>
> The number member in the Cost class should be a Decimal, not a string.
> The entry printer should probably error out if this is not the case, but
> it does not.
>

Nice catch, thanks.

I should figure out how to get mypy working on this code; this is the
second or
third time a simple type error has bitten me.

> (PS: Also not sure how to omit links.  If I return `None`, `""`, or
> > `{}`, the importer crashes.  If I return `{None}` it complete but
> > renders the annoying ^None link....)
>
> links and tags are sets. If you don't want any links or tags just assign
> an empty set. Somehow you figured this out for tags but not for links.
>

Ooof.  {} is not an empty set, it's an empty associative array.  Python
is not my strongest (or favorite) language.  The code I was working
from used data.EMPTY_SET for the tags and I didn't put two and two
together and realize that's what I should use for tags too.  (Or `set()`)


> One way to discover the data structure corresponding to a given
> transaction is to write its text representation and parse it with the
> beancount parser:
>
> from beancount.parser import parser
>
> entries, errors, options = parser.parse_string("""
> 2018-01-01 * "Bought 2.0 ABC for $204.00 USD"
>    Assets:MyInstitution:ABC      2.0 ABC {102.00 USD} @ 102.00 USD
>    Assets:MyInstitution:USD  -204.00 USD
> """)
>
> print(entries)
>

Great recipe, thanks, this will be handy.


>
>
> 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 beancount+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/beancount/5385377a-06a9-be25-50d3-d2d88fd8329f%40grinta.net
> .
>

-- 
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 beancount+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/CAFXPr0vNcyZevkczQ5XxKipqyDpmCu8dHwaJV8wYuLSPbMtDgQ%40mail.gmail.com.

Reply via email to