tag:infinitekind.tenderapp.com,2009-01-14:/discussions/moneydance-development/7257-create-new-transaction-jpype-packageInfinite Kind: Discussion 2022-05-28T20:50:25Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T14:00:37Z2022-04-06T14:00:37ZCreate new transaction (Jpype package)<div><p>(I won't comment on the use of JPype to update the MD dataset from outside MD)...</p>
<p>You certainly MUST do this:<br>
new_txn.syncItem()</p>
<p>I'm not sure you need to do this:<br>
accountBook.getTransactionSet().addNewTxn(new_txn)</p>
<p>And I'm certain you do NOT need to do this:<br>
accountBook.refreshAccountBalances()</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T14:07:31Z2022-04-06T14:07:31ZCreate new transaction (Jpype package)<div><p>The odd thing is that .addNewTxn() actually does a .syncItem() so it may be that you have a different issue with your environment.. For example, if the sync engine is not running, then it may not be writing a .txn file to the ./safe/tiksync/out. NOTE: your dataset (trunk) does not get written out to disk until restart of MD when the .txn files are re-read, processed into memory and then a save to disk occurs.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T14:11:04Z2022-04-06T14:11:04ZCreate new transaction (Jpype package)<div><p>I would also do a new_txn.setEditingMode() after ParentTxn() too.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T14:12:52Z2022-04-06T14:12:52ZCreate new transaction (Jpype package)<div><p>FYI - Based on @dalefurrow's original scripts, I also played around with ways to launch MD - purely for 'fun'.. You can find these at the end of my site:<br>
<a href="https://yogi1967.github.io/MoneydancePythonScripts/">https://yogi1967.github.io/MoneydancePythonScripts/</a></p>
<p>(note: you play at your own (data) risk 😉 )</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T15:20:12Z2022-04-06T15:20:12ZCreate new transaction (Jpype package)<div><p>Thanks for all the valuable tips, Stuart! Unfortunately I have no success. The strange part is that I don't receive no errors at all. Is there maybe some kind of commit for the transaction?</p>
<p>Thanks again.</p></div>gmeirellesstag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T15:23:29Z2022-04-06T15:23:29ZCreate new transaction (Jpype package)<div><p>Sorry I didn`t see your last post. Oh really? I love your scripts dude. I was using many of your content to learn how to create an extension. I will review it once again, thanks a lot!</p></div>gmeirellesstag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T15:38:02Z2022-04-06T15:38:02ZCreate new transaction (Jpype package)<div><p>I also just tried with your code... Oddly I could not get the split to stick.. So, here is some code that does work for me.... in Moneybot...</p>
<pre>
<code>from com.infinitekind.moneydance.model import Account, ParentTxn, SplitTxn, AbstractTxn
from com.moneydance.apps.md.controller import Util
from com.infinitekind.util import DateUtil
MD_REF = moneydance
book = MD_REF.getCurrentAccountBook()
a_id = "77d3dc2b-9547-49ba-86ad-ceb0395cc592"
c_id = "a858684e-f7cc-46e1-acc4-b1e4c501ecc0"
acct = MD_REF.getCurrentAccountBook().getAccountByUUID(a_id)
cat = MD_REF.getCurrentAccountBook().getAccountByUUID(c_id)
print "Acct: %s" %(acct)
print "Cat: %s" %(cat)
desc = "Test Txn - hello"
check = "1234"
memo = "this is a memo"
transdate = 20220203
amount = -222
rate = 1.0
new_txn = ParentTxn.makeParentTxn(book, transdate, transdate,DateUtil.getUniqueCurrentTimeMillis(), check, acct, desc, memo, -1L, 30)
txn_split = SplitTxn.makeSplitTxn(new_txn, amount, rate, cat, memo, -1L, 0)
new_txn.addSplit(txn_split)
print "------"
print "TxnSet count before:", book.getTransactionSet().getTransactionCount()
new_txn.syncItem()
#book.getTransactionSet().addNewTxn(new_txn)
print new_txn.getSyncInfo().toMultilineHumanReadableString()
print "------"
print "Did I find txn in TxnSet?", new_txn in book.getTransactionSet()
print "TxnSet count after:", book.getTransactionSet().getTransactionCount()
print "------"</code>
</pre>
<p>So, please run in Moneybot first, to prove it works, and then try it out your way and see if it fails.... If it fails, then it's your 'environment'....</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T16:05:39Z2022-04-06T16:05:39ZCreate new transaction (Jpype package)<div><p>Yes, indeed the problem should be in my approach. via Moneybot it worked perfectly.<br>
I reproduced the same code by Jpype, it does recognize the transaction in the execution, but when I open the moneydance it`s not there. Also, if I run the script again, the transaction is not found anymore and the counter starts back from 2.</p>
<h2><a name="i-will-dig-into-this-thanks-a-lot-for-the-help-so-far-" class="anchor" href="#i-will-dig-into-this-thanks-a-lot-for-the-help-so-far-"></a>I will dig into this, thanks a lot for the help so far!</h2>
<p>TxnSet count before: 2<br>
0.acctid: 4a9888c9-3619-4c6a-b08b-ad26e11ac2cd<br>
0.desc: this is a memo<br>
0.id: e8227628-3b5a-4d24-a118-e3dcaa659ce6<br>
0.obj_type:<br>
0.oldid: -1<br>
0.pamt: -222<br>
0.samt: 222<br>
acctid: 7b459e38-ce6c-4d0c-8881-f22ffc48e575<br>
chk: CARD-282567677<br>
desc: Test Txn - hello<br>
dt: 20220406<br>
dtentered: 1649260720428<br>
id: 4bfbe0f9-c640-4dc6-a075-78f062338e3e<br>
memo: this is a memo<br>
obj_type: txn<br>
oldid: -1<br>
stat: x<br>
td: 20220406<br>
ts: 1649260720503</p>
<hr>
<p>Did I find txn in TxnSet? True</p>
<h2><a name="txnset-count-after-4-" class="anchor" href="#txnset-count-after-4-"></a>TxnSet count after: 4</h2></div>gmeirellesstag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T16:16:09Z2022-04-06T16:16:48ZCreate new transaction (Jpype package)<div><p>Let me take advantage to kindly ask you some guidance. I have some development background but I<code>m a beginner in Python, the reason I</code>m trying like this, is that I could make the communication with the bank work in Python and it`s distributed in many files across my project.</p>
<p>According to your experience, what`s the easiest way to put it inside moneydance? Can I compile that and run as a Moneybot script for example?</p>
<p>Thanks a lot.</p></div>gmeirellesstag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T16:26:21Z2022-04-06T16:26:21ZCreate new transaction (Jpype package)<div><p>So I am certain it's the fact that the sync engine etc is not running.....</p>
<p>When you run your code, does a .txn file get created? (Check both when doing in Moneybot and also through your method).</p>
<p>In simple terms, when the GUI is loaded by calling .getUI(), MoneydanceGUI does lots of important stuff, including firing up the SyncManager and start background syncing. The BackgroundOpsThread also gets started...</p>
<p>My guess is that the stuff you need is in there somewhere.</p>
<p>Personally, I wouldn't be playing with this....</p>
<p>Why not launch MD from the command line, and auto run an import, or python script, with auto quit afterwards. This way you get the full MD 'experience' and your updates will work properly....</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T16:28:16Z2022-04-06T16:28:16ZCreate new transaction (Jpype package)<div><p>Are you asking whether you could write your Python (Jython) code to run inside Moneydance as a script - or extension? The answer is yes. The only issue will be access to your imported libraries.. Is this just for you, or to distribute to others?</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T16:31:13Z2022-04-06T16:31:13ZCreate new transaction (Jpype package)<div><p>Refer this link to see how to import your own libraries:<br>
<a href="https://infinitekind.tenderapp.com/discussions/moneydance-development/5684-importing-own-python-modules">https://infinitekind.tenderapp.com/discussions/moneydance-developme...</a></p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T16:32:38Z2022-04-06T16:32:38ZCreate new transaction (Jpype package)<div><p>Yes, something like that, since I have this script 'working' in Python it will be great. It`s just for my personal use. I will review this link. Thanks mate</p></div>gmeirellesstag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T16:34:20Z2022-04-06T16:34:20ZCreate new transaction (Jpype package)<div><p>About your suggestion to launch MD from the command line and auto run an import, seems interesting, do you have an example to share?</p></div>gmeirellesstag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T16:35:56Z2022-05-28T20:50:25ZCreate new transaction (Jpype package)<div><p>.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-06T16:47:40Z2022-04-06T16:47:40ZCreate new transaction (Jpype package)<div><p>Moneydance launch parameters:</p>
<pre>
<code># Usage:
# Parameter: '-d' is passed by default by this script and turns on MD DEBUG mode
# Parameter: '-v' prints the current version
# Parameter: datasetname will open the specified dataset - specify the full path wrapped in "quotes"
# Parameter: pythonscriptname.py adds script to a list of scripts to execute (but this seems to then be ignored)
# Parameter: importfilename executes file import (mutually exclusive to datasetname option)
# Parameter: '-invoke_and_quit=x' will pass along a string that you can to invoke an 'fmodule' (extension) and quit (not showing UI)
# executes Main.showURL(invokeAndQuitURI)
# e.g. 'moneydance:fmodule:test:test:customevent:magic'
# (e.g. my own extension with an id of test defines it's own command called 'test:customevent:magic'
# (there are other variations of this parameter and with ? instead of ':' for parameters.....
# Parameter: '-invoke=x' Same as -invoke_and_quit but does launch the UI first and doesn't quit...!
# MD2021.2(3088): Adds the capability to set the encryption passphrase into an environment variable to bypass the popup question
# Either: md_passphrase= or md_passphrase_[filename in lowercase format]</code>
</pre></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-07T10:09:02Z2022-04-07T10:09:02ZCreate new transaction (Jpype package)<div><p>For fun/experiment only... To get the txns saved you need to call .saveCurrentAccount(). With Java/Jython, this works fine (as long as you also use .setCurrentBook() earlier on). But with JPype .setCurrentBook() never seems to work and thus .saveCurrentAccount() will not work... You can work around this with book.save() in JPype() and this will save the txn.</p>
<p>Again, disclaimer.... I personally would not be updating MD this way..... Using an import file / extension would be best....</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-07T13:45:23Z2022-04-07T13:46:23ZCreate new transaction (Jpype package)<div><p>Everything worked perfectly. Thanks a lot Stuart, you<code>re a Moneydance</code>s God! Also, thank you for all recommendation, everything is experimental since I`m getting experience as a Hobby. I use Moneydance since 2015 and having the opportunity to do 'useful things' as a way of personal study is amazing. Thank you again for all your help and available content.</p></div>gmeirellesstag:infinitekind.tenderapp.com,2009-01-14:Comment/537155022022-04-07T16:51:29Z2022-04-07T16:51:29ZCreate new transaction (Jpype package)<div><p>👍 😃</p>
<p>Mr Toolbox</p></div>Stuart Beesley (Mr Toolbox)