Creating new txn

davidcullen's Avatar

davidcullen

14 Jul, 2021 04:36 AM

It's been a while since I used md jython to create txns, so forgive me for forgetting something which should be obvious.
I"m currently using this code to create txns:

newTxn =  ParentTxn(book)
newTxn.setDescription("Debit interest apportioned")
newTxn.setDateInt(20170630)
newTxn.setTaxDateInt(20170630)
newTxn.setDateEntered(20170630)  # this does not seem to be necessary?
newTxn.setAccount(acc1) # acc1 is a properly defined Account
txnSplit = SplitTxn(newTxn)
txnSplit.setAmount(9999)
txnSplit.setParentAmount(1.0, -100) # this does not seem to be necessary?
txnSplit.setAccount(acc2) # acc2 is a properly defined Account
txnSplit.setKeywords(["trilogy"])
txnSplit.setDescription("Apportioned amount")
txnSplit.setClearedStatus(RECONCILING)
newTxn.addSplit(txnSplit)
txnSplit = SplitTxn(newTxn)
txnSplit.setAmount(9999)
txnSplit.setParentAmount(1.0, -200) # # this does not seem to be necessary?
txnSplit.setAccount(acc2)
txnSplit.setKeywords(["bell"])
txnSplit.setDescription("Apportioned amount")
txnSplit.setClearedStatus(RECONCILING)
newTxn.addSplit(txnSplit)
newTxn.setClearedStatus(RECONCILING)
Both of these alternatives seem to work correctly:
Alternative 1:
newTxn.syncItem()
book.refreshAccountBalances()
or:
Alternative 2:
book.getTransactionSet().addNewTxn(newTxn)
book.refreshAccountBalances()
The above seems to work.
My questions are:
Which of the above alternatives is preferred? and:
Are the steps above shown as not seeming to be necessary required?
  1. 1 Posted by Stuart Beesley ... on 14 Jul, 2021 08:25 AM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    Well, guess what book.getTransactionSet().addNewTxn(newTxn) actually does......

    newTxn.syncItem()

    that's it.... So there is actually no difference...

    ;->

  2. 2 Posted by davidcullen on 15 Jul, 2021 03:42 AM

    davidcullen's Avatar

    Stuart,
    As usual, thanks.
    David

  3. davidcullen closed this discussion on 15 Jul, 2021 03:42 AM.

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