Last active
December 23, 2017 14:46
-
-
Save LiosK/4a293b75145c90fb61d9b4492b4603e0 to your computer and use it in GitHub Desktop.
gncxml - join transfer account information if a transaction consists of only two splits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gncxml | |
def join_transfer(sp): | |
pairs = sp.reset_index() \ | |
.groupby(["trn_idtype", "trn_id"]) \ | |
.filter(lambda x: len(x) == 2) | |
dup = pairs[["trn_idtype", "trn_id", "idtype", "id"]] \ | |
.join(pairs.set_index(["trn_idtype", "trn_id"]) \ | |
.add_prefix("transfer_"), \ | |
on=["trn_idtype", "trn_id"]) | |
dedup = dup[(dup["id"] != dup["transfer_id"]) \ | |
| (dup["idtype"] != dup["transfer_idtype"])] \ | |
.drop(columns=["trn_idtype", "trn_id"]) | |
return sp.join(dedup.set_index(["idtype", "id"])) | |
try: | |
book = gncxml.Book("mybook.gnucash") | |
except OSError as err: | |
sys.exit(err) | |
join_transfer(book.list_splits()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment