proper way to delete a transaction?
Hi, I did find deleteItem() in https://infinitekind.tenderapp.com/discussions/moneydance-development/2642-jython-delete-txn
and I get that. my question is if I want to delete a transaction, should I delete all the splits and also delete the parent? Or if I just find the parent and delete it that's fine. Just want to make sure I don't end up with some odd orphaned splits or anything like that.
Thanks!
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 1 Posted by Sean Reilly on Mar 29, 2021 @ 10:30 PM
Hi Jim,
Great questions! To completely delete a transaction please get the parent and call deleteItem() on that. All transactions have a .getParentTxn() method so you can reliably call .getParentTxn().deleteItem().
However in some cases you might not want to delete every part of a transaction, such as when you have a SplitTxn that is part of a multi-split transaction (such as most transactions in investment accounts). In cases like those you'd want to check if you have a split that is part of a multi-split transaction. So maybe something like the following:
Thanks,
Sean
--
Sean Reilly
Developer, The Infinite Kind
https://infinitekind.com
2 Posted by J C on Mar 30, 2021 @ 02:05 AM
Thanks Sean!
Your response of course triggers a thought I want to confirm. I'm
getting the transaction from a set like this:
txns =
moneydance_data.getTransactionSet().getTransactionsForAccount(BankAccountName)
My understanding is that because I'm using the name of a bank account
and not a 'category', then the txn set would only include parent
transactions. Is that a correct assumption? I'm currently skipping this
step: ptxn = txn.getParentTxn() , but wondering if I'm at any risk of
buggering things up.
(In my case I'm not looking to preserve any splits so it seems like just
deleting the parent will also delete the splits.)
I was also wondering ..if a ParentTxn has multiple splits and you
ParentTxn.removeSplit() on one of them (and don't delete it), what
happens to that split? Will it delete itself or will it get orphaned and
hang around somehow/where?
Thanks,
Jim
3 Posted by Stuart Beesley ... on Mar 30, 2021 @ 04:20 AM
You will (may) get both parents and splits in your txn set even when you select an account. This is because txfrs between accounts can be initiated from either account / ‘side’. Thus if you get a split it may be the other half of an account txfr or even the Xfr part of a investment BuyXfr or sell Xfr.
4 Posted by Stuart Beesley ... on Mar 30, 2021 @ 05:22 AM
Just checked... Yup if you use ParentTxn.removeSplit() then you should call ParentTxn.syncItem() afterwards; that's it. But take care if you are deleting the last split - as Sean mentions above. Also take care; ideally use ParentTxn.setEditingMode() if you are going to make multiple changes to a parent before you call .syncItem().
5 Posted by Jim on Mar 30, 2021 @ 03:07 PM
Thanks for the clarification Stuart!
Jim
Support Staff 6 Posted by Sean Reilly on Mar 30, 2021 @ 03:44 PM
Hi Jim,
Stuart's answer to the first question is correct.
For the second question, a deleted split should only stick around if you keep a reference to it... so as long as you (and other extensions) don't hold onto it, it will be garbage collected by java and never seen again.
Cheers,
Sean
System closed this discussion on Jun 29, 2021 @ 03:50 PM.