Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autosync: looking up payee and offset account happens differently #131

Open
claytonrcarter opened this issue Oct 21, 2021 · 1 comment
Open

Comments

@claytonrcarter
Copy link

claytonrcarter commented Oct 21, 2021

Hi! Thank you for your work on ledger-autosync. I'm new to ledger and ledger-autosync, so perhaps this has already bee covered somewhere. If, I'm sorry.

I can't tell if this is a bug, or just me being new and not knowing my way around, but I'm tying myself in knots trying to figure out how autosync and offset account lookup works. It's pretty easy to get the name to be be looked up via AutosyncPayee, but I can only get the offset account to be looked up if I explicitly specify a payee name format via --payee-format '{payee}'.

Here's my homework...

Given a ledger w/ this transaction:

2021-03-21 * Square Deposit
  ; AutosyncPayee: ACH Deposit Square Inc
  Bank:Checking      $89.00
  Undeposited Funds  $-89.00

and an OFX file w/ a transaction matching this snippet:

      <TRNAMT>504.50
      <NAME>ACH Deposit Square Inc
      <MEMO>TYPE: 211018P2 CO: Square Inc

then, this is what I see:

# first, w/o connecting l-a to my ledger file
$ ledger-autosync  file.OFX -a Assets:Bank:Checking

2021/10/18 ACH Deposit Square Inc TYPE: 211018P2 CO: Square Inc
    Bank:Checking                                         $504.50
    Expenses:Misc                                        -$504.50

# next, w/ connecting it to my ledger file, but w/o the payee-format
$ ledger-autosync -l journal.ledger  file.OFX -a Bank:Checking

2021/10/18 Square Deposit TYPE: 211018P2 CO: Square Inc
    Bank:Checking                                         $504.50
    Expenses:Misc                                        -$504.50

# finally, w/ my ledger file AND payee-format
$ ledger-autosync -l journal.ledger  file.OFX -a Bank:Checking --payee-format '{payee}'
2021/10/18 Square Deposit
    Bank:Checking                                         $504.50
    Assets:Undeposited Funds                             -$504.50

I've also tried to put the full name + memo "name" into the AutosyncPayee field, but that doesn't work either.

The more I tinker w/ the code and play w/ it, I think that this all swirls around mk_dynamic_account and load_payees. mk_dynamic_account is called w/ self.format_payee(txn), and then calls out to get_account_by_payee w/ the formatted payee name. get_account_by_payee then calls load_payees and then uses the passed (formatted) payee to filter the accounts. However, it looks (again, to me, not a python dev) like load_payees is just loading the payees based on the results of calling ledger csv show --actual, ie the payees that ledger knows about, not that I've configured via AutosyncPayee or payee_format.

So, stepping back up, get_account_by_payee is using the formatted payee name to query the dictionary of payees and accounts, and that will only work if either all of my ledger transactions have payees that match payee_format. ... which ... I guess might not be a bug, but a configuration issue on my end?? I don't know.

Possibly related, but what got me started on this is that essentially all of the transactions in my OFX file (ie nearly all of my transactions) have the date or some sort of transaction reference number (like the actual POS transaction, not the ledger transaction) included in the OFX memo field, so the default format of {payee} {memo} means that they're all essentially unique. Again, I can get around this w/ --payee-format '{payee}', but then I completely lose the memo, which sometimes includes useful information.

Sorry to be rambling about this. This is probably all just me trying to learn my way around.

Thanks again for ledger-autosync!

@egh
Copy link
Owner

egh commented Oct 26, 2021

I admit I've kind of lost track of how the automatic payee matching works, but I think you're correct - the transaction number in the payee line is preventing the payee from matching. ledger-autosync calls ledger -f fixtures/checking.lgr csv show --actual and creates a map between the payee and the account in that csv file. So when the payee is Square Deposit it matches, but when its Square Deposit TYPE: 211018P2 CO: Square Inc it is not matching the older entries, so it's not picking up the account name.

It would probably be possible to add some sort of fuzzy matching on the payee line.

Alternately, you could save the transaction number in a metadata comment. In the long term we could add a new option for a "comment line" format, e.g.

ledger-autosync file.OFX -a Bank:Checking --transaction-comment-format="stripeinfo: {memo}" --payee-format="{payee}"
...
2021/10/18 Square Deposit
    ; stripeinfo: TYPE: 211018P2 CO: Square Inc
    Bank:Checking                                         $504.50
    Expenses:Misc                                        -$504.50

for now you could hack this together (though it doesn't seem like a great idea in the long term:

$ ledger-autosync file.OFX -a Bank:Checking --payee-format $'{payee}  \n    ; stripeinfo: {memo}'
2021/10/18 Square Deposit
    ; stripeinfo: TYPE: 211018P2 CO: Square Inc
    Bank:Checking                                         $504.50
    Expenses:Misc                                        -$504.50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants