tag:infinitekind.tenderapp.com,2009-01-14:/discussions/moneydance-development/7400-update-cash-balance-after-adding-split-transactionInfinite Kind: Discussion 2022-08-29T14:30:18Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/544743022022-05-30T04:53:10Z2022-05-30T04:53:10Zupdate cash balance after adding split transaction<div><p>I haven’t debugged your code, but a BuyXfr would need an account/category to transfer the cash in/out. I don’t see you setting this in the above. So I can properly understand what you are trying to do, can you highlight a transaction, right click, show record details. Can you do this before and after a successful change and post those details?</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/544743022022-05-30T05:13:09Z2022-05-30T05:13:09Zupdate cash balance after adding split transaction<div><p>Also, I'm a bit confused as why you are setting the "invest.splittype" parameter to "inc" when you said this is/was a Buy transaction? For example, here is a Buy and a BuyXfr</p>
<p>Buy that reduces cash balance<br></p>
<pre>
<code>0.acctid: 2005787b-f161-4dea-b360-9dc192822b78
0.desc: Desc
0.id: 35b6283b-6b6d-4c19-b5c9-c8c0fcda6368
0.invest.splittype: sec
0.obj_type:
0.pamt: -99999
0.samt: 10100000
acctid: a5f09061-2c42-4a18-805f-7cf82deb0614
chk: cheque
desc: Desc
dt: 20220501
dtentered: 1653886506642
id: 037f3491-2d02-42ab-8602-468f9ec89b88
invest.txntype: buy
memo: memo
obj_type: txn
oldid: -1
td: 20220501
ts: 1653886558566
xfer_type: xfrtp_buysell</code>
</pre>
<p>BuyXfr that does not reduce cash balance, but transfers the cash in from elsewhere<br></p>
<pre>
<code>0.acctid: 2005787b-f161-4dea-b360-9dc192822b78
0.desc: Desc2
0.id: d6fd1587-3b81-44b3-89af-7a99ababfe76
0.invest.splittype: sec
0.obj_type:
0.pamt: -119158468
0.samt: 20200000
0.tags:
1.acctid: 083e4a09-b633-42ae-877a-110f7db54bc0
1.desc: Desc2
1.id: 8c79ef59-e025-4cd2-b0b0-71abd8251159
1.invest.splittype: xfr
1.obj_type:
1.pamt: 119158468
1.samt: -119158468
acctid: a5f09061-2c42-4a18-805f-7cf82deb0614
chk: cheque2
desc: Desc2
dt: 20220502
dtentered: 1653886667124
id: 8f8e2a5e-8bc9-4cdd-bd32-32db87a28168
invest.txntype: buyx
memo: memo2
obj_type: txn
tags:
td: 20220502
ts: 1653886694355
xfer_type: xfrtp_buysellxfr</code>
</pre>
A BuyXfr will always have an additional split...
<p>So, please can you post the txn details (screenshots of before and after and the show record details before and after)?</p>
<p>Tip, the com.infinitekind.moneydance.model.InvestFields class might be your friend here:</p>
<pre>
<code>https://infinitekind.com/dev/apidoc/com/infinitekind/moneydance/model/InvestFields.html</code>
</pre>
<pre>
<code>fields = InvestFields()
fields.setFieldStatus(parentTxn) # Just do this on Parent transactions
...make changes to fields
fields.storeFields(parentTxn)
fields.syncItem()</code>
</pre>
<p>This might also help:</p>
<pre>
<code>print parentTxn.getSyncInfo().toMultilineHumanReadableString()</code>
</pre></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/544743022022-05-30T05:42:50Z2022-05-30T05:42:51Zupdate cash balance after adding split transaction<div><p>Stuart,</p>
<p>Thanks a lot for your feedback. The BuyX should be the correct type as transactions are stock shares directly from the employer.</p>
<p>Here is the original "Buy" transaction:<br></p>
<pre>
<code>0.acctid: 48f3085f-893e-4341-ae78-a6ac110eb833
0.desc:
0.id: 65c32061-c718-4d2c-bcdc-8db169b76550
0.invest.splittype: sec
0.obj_type:
0.pamt: -14542
0.samt: 8029818
acctid: 9a0c2d8f-10e8-4a5e-ba6a-38337bf60eb7
chk:
desc:
dt: 20220527
dtentered: 1653888120975
id: 0e9cd320-c06a-4440-a1f4-216790c44ba0
invest.txntype: buy
memo:
obj_type: txn
ol.match-status: y
ol.match-type: 0
ol.orig-memo:
ol.orig-payee:
ol_fitid_1: 97276066E1537532279S4
oldid: -1
td: 20220527
ts: 1653888120975
xfer_type: xfrtp_buysell</code>
</pre>
After running the script<br>
<pre>
<code>0.acctid: 48f3085f-893e-4341-ae78-a6ac110eb833
0.desc:
0.id: 65c32061-c718-4d2c-bcdc-8db169b76550
0.invest.splittype: sec
0.obj_type:
0.pamt: -14542
0.samt: 8029818
acctid: 9a0c2d8f-10e8-4a5e-ba6a-38337bf60eb7
chk:
desc:
dt: 20220527
dtentered: 1653888120975
id: 0e9cd320-c06a-4440-a1f4-216790c44ba0
invest.txntype: buyx
memo:
obj_type: txn
ol.match-status: y
ol.match-type: 0
ol.orig-memo:
ol.orig-payee:
ol_fitid_1: 97276066E1537532279S4
oldid: -1
td: 20220527
ts: 1653888225604
xfer_type: xfrtp_buysellxfr</code>
</pre>
After pressing "enter"<br>
<pre>
<code>0.acctid: 48f3085f-893e-4341-ae78-a6ac110eb833
0.desc:
0.id: 65c32061-c718-4d2c-bcdc-8db169b76550
0.invest.splittype: sec
0.obj_type:
0.pamt: -14542
0.samt: 8029818
1.acctid: 58100c4b-d4d5-4db8-adaf-ed1a256cdfe2
1.desc:
1.id: d1478cba-ce77-411d-ab8a-60f8ef5bb2c5
1.invest.splittype: xfr
1.obj_type:
1.pamt: 14542
1.samt: -14542
acctid: 9a0c2d8f-10e8-4a5e-ba6a-38337bf60eb7
chk:
desc:
dt: 20220527
dtentered: 1653888120975
id: 0e9cd320-c06a-4440-a1f4-216790c44ba0
invest.txntype: buyx
memo:
obj_type: txn
ol.match-status: y
ol.match-type: 0
ol.orig-memo:
ol.orig-payee:
ol_fitid_1: 97276066E1537532279S4
oldid: -1
td: 20220527
ts: 1653888266843
xfer_type: xfrtp_buysellxfr</code>
</pre>
Besides ts changes, which are irrelevant for the discussion. It seems that script did just its job somewhat correctly, except newly added split transaction didn't get recognized until "enter" is pressed from keyboard. What could cause that?</div>H Yitag:infinitekind.tenderapp.com,2009-01-14:Comment/544743022022-05-30T06:06:47Z2022-05-30T06:06:47Zupdate cash balance after adding split transaction<div><p>Sorry, but the script is not working... You are not adding the new split line...</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/544743022022-05-30T06:10:31Z2022-05-30T06:10:31Zupdate cash balance after adding split transaction<div><p>All your script is actually doing is changing this:<br>
invest.txntype: buyx</p>
<p>When you then go to press enter, MD knows the data is wrong and is doing all the work...</p>
<p>Your script needs to add a splitTxn for the actual xfr (and not change the buy split). Best best is to use the InvestFields class</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/544743022022-05-30T06:25:51Z2022-05-30T06:32:02Zupdate cash balance after adding split transaction<div><p>.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/544743022022-05-30T06:33:40Z2022-05-30T06:43:06Zupdate cash balance after adding split transaction<div><p>.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/544743022022-05-30T06:46:07Z2022-05-30T06:46:07Zupdate cash balance after adding split transaction<div><p>Last update:.....Do something like this (not tested) on the ParentTxn:</p>
<pre>
<code>from com.infinitekind.moneydance.model import InvestFields, ParentTxn
if not isinstance(txn, ParentTxn): continue
fields = InvestFields()
fields.setFieldStatus(txn)
fields.txnType = InvestTxnType.BUY_XFER
fields.hasXfrAcct = True
fields.xfrAcct = THE_ACCOUNT_OBJECT_FOR_TXFR_ACCT_HERE
fields.storeFields(txn)
txn.syncItem()</code>
</pre>
<p>I presume you already have a reference to THE_ACCOUNT_OBJECT_FOR_TXFR_ACCT_HERE (uuid: 58100c4b-d4d5-4db8-adaf-ed1a256cdfe2)? If not, and if the xfr account never changes, then for now you can do once this at the beginning before you iterate the txns:</p>
<pre>
<code>xfrAcct = moneydance.getCurrentAccountBook().getAccountByUUID("58100c4b-d4d5-4db8-adaf-ed1a256cdfe2")</code>
</pre>
<p>and use:</p>
<pre>
<code>fields.xfrAcct = xfrAcct</code>
</pre></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/544743022022-05-30T11:48:26Z2022-05-30T11:48:32Zupdate cash balance after adding split transaction<div><p>Stuart,</p>
<p>Thanks a lot for the suggestion. Your code works like a charm!</p></div>H Yitag:infinitekind.tenderapp.com,2009-01-14:Comment/544743022022-05-30T12:15:39Z2022-05-30T12:15:39Zupdate cash balance after adding split transaction<div><p>Kool! 👍 😃</p>
<p>The InvestFields is a very useful and easy class to use and handles the complexity of the underlying record format….</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/544743022022-05-30T14:21:19Z2022-05-30T14:21:25Zupdate cash balance after adding split transaction<div><p>Thanks for the tip! You're a lifesaver!</p></div>H Yi