New Transactions using Python

Jim's Avatar


24 Aug, 2020 01:42 AM

Ok, dug around and found a few things, but have some questions...
So starting with this:
It mentions setting a source account on the ParentTxn and target account on the SplitTxn.
Does 'source account' here mean the bank account and 'target account' mean the 'Category'?

Then found this:
Looking at that code, it looks like it just sets 'categories'. Looking at that code I think it is missing the concept of a 'source account' (.i.e. bank acccount)...?

  1. 1 Posted by Jim on 24 Aug, 2020 01:54 AM

    Jim's Avatar

    OK. So did some testing and I think I was correct. So I have this now which seems to work:

    from com.infinitekind.moneydance.model import *
    root = moneydance.getRootAccount()
    book = moneydance.getCurrentAccountBook()
    txnset = book.getTransactionSet()
    bankaccount = root.getAccountByName("TEST")

    txn = ParentTxn(book) txn.setDescription("TestTxn") txn.setDateInt(20200824) txn.setDateEntered(20200824) txn.setAccount(bankaccount) txn.setMemo('testMemo')

    category = root.getAccountByName("Automotive") txnSplit = SplitTxn(txn) txnSplit.setAmount(555) txnSplit.setParentAmount(1.0, -555) txnSplit.setAccount(category) #txnSplit.setKeywords(["Trilogy"]) txnSplit.setDescription("Split1 Test") txn.addSplit(txnSplit)

    category = root.getAccountByName("Education") txnSplit = SplitTxn(txn) txnSplit.setAmount(111) txnSplit.setParentAmount(1.0, -111) txnSplit.setAccount(category) #txnSplit.setKeywords(["Bell"]) txnSplit.setDescription("Split2 test") txn.addSplit(txnSplit)

  2. 2 Posted by Jim on 24 Aug, 2020 01:57 AM

    Jim's Avatar

    Could also change the first line to just:

    from com.infinitekind.moneydance.model import ParentTxn, SplitTxn
  3. Support Staff 3 Posted by Sean Reilly on 24 Aug, 2020 02:58 PM

    Sean Reilly's Avatar

    Hi Jim,

    Yes, in most cases the source account is the bank account, but we don't really use that terminology in moneydance itself. In Moneydance any transaction is a movement of value from one account to another (or to/from multiple others in the case of multi-split transactions). So each transaction must have at least two "sides". One side is always represented by the ParentTxn, which is usually the account in which the transaction was entered. Then there are one or more splits, where each split specifies the other account (or category) and the amount.

    It gets more complicated with inter-currency transactions, cleared status, tags, etc, but that's the basics.

    So to simplify the example you linked to...

    txn = ParentTxn(book)
    txn.setDescription("Example Transaction")
    txn.setAccount(account1) // <- this is where your "bank" account is usually specified

    txnSplit = SplitTxn(txn)
    txnSplit.setAccount(account2) // <- this is where your category is usually specified

    txn.syncItem() // <- saves the transaction


  4. Support Staff 4 Posted by Sean Reilly on 24 Aug, 2020 02:58 PM

    Sean Reilly's Avatar

    Oh yes! Sorry, you've got it right. I sent my last message before seeing your subsequent replies.

  5. System closed this discussion on 23 Nov, 2020 03:00 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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