isaacharrisholt / quiffen

Quiffen is a Python package for parsing QIF (Quicken Interchange Format) files.
MIT License
34 stars 30 forks source link

Handle to_account transfers in split transactions #95

Closed lcmcninch closed 1 week ago

lcmcninch commented 2 weeks ago

I have one more for you.

Problem

It looks like when a transaction is a transfer (indicated by [Account Name] in the category field, it is handled properly and the account name is applied to the to_account field and the category is left None.

However, if this kind of transfer occurs in a split, it isn't handled the same way. In the Split, the account name is assigned to category and not to_account.

Here's an example transaction in the "Checking" account. It is a $10 transfer with $9 going to the "Savings" account as a transfer, and $1 going to a Cash category.

^
D9/ 4'24
U-10.00
T-10.00
PSome Payee
L--Split--
S[Savings]
$-9.00
SCash
$-1.00
^

Here's how that is currently parsed.

>>>print(qif.accounts["Checking"].transactions["Bank"][6].splits[0])

Split:
    Amount: -9.00
    Category: [Savings]
    Percent: 90.000000000

Suggested Solution

See https://github.com/isaacharrisholt/quiffen/compare/main...lcmcninch:quiffen:split_to_account for my suggested solution.

In Transaction.from_list, when parsing a split transaction, we apply the same logic as when parsing a non-split transaction. Look for the opening bracket "[". If found, set to_account instead of category. With that change, I now get:

print(qif.accounts["Checking"].transactions["Bank"][6].splits[0])
Split:
    Amount: -9.00
    To Account: Savings
    Percent: 90.000000000

Thoughts? If you agree, I can submit a PR.

isaacharrisholt commented 2 weeks ago

Looks good! Feel free to combine this with the PR for #94

lcmcninch commented 2 weeks ago

Perfect, will-do. Thanks again!