Simple Jython example to create a new account
I have successfully created some Jython scripts to import data from csv files and add to existing accounts in my MD2015 MoneyDance file. I now have a need to create new sub-accounts that may not exist (specifically a sub-account of a parent liability account) and am looking for a simple example from that part of the code to help me see how to implement this.
Any pointers on this is greatly appreciated. In general, having some more example code in the API documentation will be helpful to newer developers like me!
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
1 Posted by boschen on 03 Mar, 2016 09:57 PM
I think I might have figured it out-does this look right as best practice? It does add the new accounts.
The following is for a top level liability account under root:
from com.infinitekind.moneydance.model import ParentTxn, SplitTxn, AbstractTxn, Account
root= moneydance.getRootAccount()
book= moneydance.getCurrentAccountBook()
new_account = Account.makeAccount(book, root.AccountType.LIABILITY, root)
new_account.setAccountName('Test Name Here')
and to put a sub-account under this one:
new_sub = Account.makeAccount(book, root.AccountType.LIABILITY, new_account)
new_sub.setAccountName('Sub Name Here')
2 Posted by Ian L on 07 Mar, 2016 01:39 PM
Hi boschen,
What you're doing should work fine. The only thing you should add is a call to .syncItem() on each account after it's been fully created. So, something like this:
That will ensure the accounts automatically show up in the account hierarchy immediately, instead of not showing until a restart.
Ian
Infinite Kind Support
3 Posted by boschen on 07 Mar, 2016 06:07 PM
Perfect, thanks Ian.
boschen closed this discussion on 08 Mar, 2016 04:38 AM.