Converting Investment Transaction to DIVIDEND_REINVEST
Hi
My brokerage sends statements that show Dividend Reinvestments but the OFX downloads are two separate transactions:
- One is InvestTxnType.DIVIDEND (technically the parent txn)
- One is InvestTxnType.BUY I want to delete the DIVIDEND transaction and convert the BUY to DIVIDEND_REINVEST. In the UI, I usually just delete the DIV transaction and change the type of the other to DivReinvest
From a code standpoint:
- The delete is easy.
- Is the conversion of the BUY to DIVIDEND_INVEST as simple as changing the transaction type or do I need to do something like:
parent_txn = txn.getParentTxn()
fields = InvestFields()
fields.setFieldStatus(InvestTxnType.DIVIDEND_REINVEST, parent_txn)
fields.storeFields(parent_txn)
parent_txn.syncItem()
Thanks in advance...
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 15 Nov, 2024 01:06 PM
Hi John,
That is very close! What I would do is something like this:
It is on my to-do list to add an option to automatically merge separate dividend and reinvest transactions.
Thanks,
Sean
--
Sean Reilly
Developer, The Infinite Kind
https://infinitekind.com
2 Posted by john.vogtle+inf... on 15 Nov, 2024 04:18 PM
Thanks, Sean. I'll give it a shot and report back!
3 Posted by john.vogtle+inf... on 29 Nov, 2024 04:53 PM
Hi Sean -
Just getting back to this after an "interesting" couple of weeks. I think I'm almost there but while the transaction now says DivReinvest, it acts in the account register like a Buy. I've attached a screen shot showing the weirdness.
If I the visibly no-op operation of setting the transaction in the UI to DivReinvest, the calculation straightens out.
Here's the current code for converting the transactions.
4 Posted by john.vogtle+inf... on 08 Dec, 2024 10:29 PM
@Sean - can you have a look at the code above and report what I might be missing...
5 Posted by Stuart Beesley ... on 09 Dec, 2024 07:13 AM
Can you right click the txn after your code runs and grab show raw details. Then noop edit it and grab a new raw details. Post both here. I suspect there’s a leftover parameter that needs clearing out. With the raw details it will be easy to spot.
6 Posted by Stuart Beesley ... on 09 Dec, 2024 07:43 AM
Ok. I haven’t tested this but taking a quick peek tells me you need to do this too:
…right before you set the fields.category
Then everything else should fire into place
Let me know?
7 Posted by john.vogtle+inf... on 09 Dec, 2024 03:15 PM
Just saw this Stuart. I'll respond back with my findings.
8 Posted by john.vogtle+inf... on 10 Dec, 2024 01:31 AM
Hey Stuart. Busy work day. Here's what I've found:
Raw Output Post Script
After "no-op" DivReinvestThe difference seems to be the addition of several lines:
I then added the
fields.hasCategory = True
to the script as you suggested and it worked like a champ!Thanks so much! Can you tell me where you found the fields documented or did you decompile a Java class to find out?
Thanks again.
-John
9 Posted by Stuart Beesley ... on 10 Dec, 2024 09:44 AM
It would be great to swap coding tips with you. You if you like, email me:
…
10 Posted by Stuart Beesley ... on 10 Dec, 2024 09:47 AM
…
11 Posted by Stuart Beesley ... on 10 Dec, 2024 09:51 AM
PS. Glad it worked. Yes your code did not trigger InvestFields to add the income split when changing the InvestType. Ideally this utility class could do with a changeInvestType() method. Setting that hasCategory field to True effectively did what was necessary for the internal code to add the missing split.
Support Staff 12 Posted by Sean Reilly on 10 Dec, 2024 09:54 AM
Hi John,
The hasCategory property is set internally to the InvestFields object based on the transaction type. I should change it to be a read-only field (or private-set). For your code, instead of this:
I recommend doing this:
which should set the hasCategory (and everything else) properly.Can you let me know if that doesn't solve the problem?
Thanks,
Sean
--
Sean Reilly
Developer, The Infinite Kind
https://infinitekind.com
Support Staff 13 Posted by Sean Reilly on 10 Dec, 2024 10:15 AM
ah yes, I see that I originally suggested the original code too... sorry about that! I'll take another look at this and actually run it to make sure it works before I send an update.
--
Sean Reilly
Developer, The Infinite Kind
https://infinitekind.com
14 Posted by john.vogtle+inf... on 11 Dec, 2024 01:25 AM
Thanks so much, Sean. I've made the changes to my code. I need to wait until the next time my Broker updates my account to see if the change you suggested works. Much appreciated.