On Sat, Oct 6, 2018 at 1:45 AM Justus Pendleton <justu...@gmail.com> wrote:

> On Friday, October 5, 2018 at 6:52:57 AM UTC+7, Jeremy Maitin-Shepard
> wrote:
>>
>>  - it includes metadata in imported entries that allow it to reliably
>> associate entries in the journal with external data, so that you don't need
>> to manually track what has already been imported.
>>
>
> Can you give a point to the code for how this works? It is something that
> individual Source implementations can override or control?
>
Yes, this is entirely controlled by the individual Source.


> I ask because I have a YNAB4 importer[1] which uses metadata on each
> transaction to achieve a similar result. In YNAB, each transaction has a
> UUID, so by shoving that in beancount metadata, I can keep track of what
> has already been imported.
>
> I'm vaguely interested in rewriting the YNAB importer to use your
> framework -- since yours has lots of other nice things -- but I don't
> really want to have to deal with re-confirming years worth of already
> imported YNAB transactions. So ideally I could have a YNAB Source in your
> framework that UUID. Is something like that possible?
>


To define a YNAB source, you could extend the Source class in
https://github.com/jbms/beancount-import/blob/master/beancount_import/source/__init__.py

In the __init__ method you would load the YNAB database into memory.

You would define a method named prepare that is given a JournalEditor
object, which has an entries property, which has the list of directives
loaded from the journal, and an accounts property that is a dict that maps
the account name str -> account Open objects.

This method would basically do everything that your existing code already
does, and it would be pretty easy to adapt it: you would use the accounts
dict provided to find which accounts have a ynab_name metadata field and
build your account_mapping dict, build up your previous_imports list (which
you might want to change to a set for efficiency) by iterating through the
entries in the journal, add any relevant warnings or errors to the
SourceResults object provided, and add any new transactions to the
SourceResults object as well.

If you wanted to avoid having to manually specify the ynab_name to
beancount account mapping, you could instead create the postings with
Expenses:FIXME as the account, and with a ynab_account_name metadata field
on each posting indicating the ynab account name, and set:

self.example_posting_key_extractors['ynab_account_name'] = None

in the __init__ method of your Source.

Then the account names would be predicted automatically, but could be
manually overridden.  (It seems like what you have already is more
convenient, though.)

The source that behaves closest to what you want to do is the amazon source
in beancount_import/source/amazon.py.

One thing I'm unclear on is what sort of workflow you want to have.

>From the documentation of your beancount-ynab project, it sounds like you
manually enter transactions into YNAB, and then periodically import them
automatically into beancount.

With beancount-import, you would still manually confirm each transaction as
it is being imported, as that lets you choose whether to import it as a new
transaction or accept a proposed match that merges it with other
transactions, and also lets you specify/confirm any unknown accounts, edit
the narration, etc.  Even in cases where you are just confirming the
transaction and there are no unknown accounts that were predicted, I still
find it useful to confirm the transaction since that lets me know about it
(as it is coming from an external source, so I haven't seen it before).

In your case, though, it sounds like you've already manually entered the
transactions in YNAB, so you don't necessarily want to manually confirm or
edit each transaction when importing into beancount.

Do you always import into YNAB manually, or do you somehow import external
data into YNAB?



>
> [1]: https://github.com/hoostus/beancount-ynab
>
>> --
> 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 post to this group, send email to beancount@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/beancount/a4287678-ff62-4a58-9ba7-f07ec7c86c4f%40googlegroups.com
> <https://groups.google.com/d/msgid/beancount/a4287678-ff62-4a58-9ba7-f07ec7c86c4f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 post to this group, send email to beancount@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beancount/CAKJfoCGHr7TuTogNTc0JeO07feyWAf023%2B7vRvAOTXGPreE_Vg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to