setAmount in Python?

Elliot's Avatar

Elliot

27 Jan, 2018 05:40 PM

Hi,

Lloyds bank unfortunately imports all transactions incorrectly into Moneydance. Credits are debits, and debits are credits. I'm trying to change the value of transactions by looping through them and *-1 to get them the right way around. There is the ability to use getValue to get the amount of the transaction, but how would I set the value?

whichAccount = "Lloyds Avios Rewards"
startdate = "2017-12-01"
enddate = "2017-12-31"

root = moneydance.getCurrentAccount()
book = moneydance.getCurrentAccountBook()

sd = int(startdate.replace("-", ""))
ed = int(enddate.replace("-", ""))
mAcc = root.getAccountByName(whichAccount) 

print "checking transactions from %s to %s" % (sd, ed)
if startdate and enddate:
  txns = book.getTransactionSet().getTransactionsForAccount(mAcc)
  for txn in txns:
    if ed >= txn.getDateInt() >= sd:
        txn.getParentTxn().setAmount(-1*txn.getValue())
  1. Support Staff 1 Posted by Sean Reilly on 02 Feb, 2018 09:38 PM

    Sean Reilly's Avatar

    Hi Elliot,

    Thanks for your message! Can I ask how you are getting the transactions into Moneydance? Is it a direct connection from within Moneydance, or are you downloading and importing a QIF or OFX file? We may already have a built-in mechanism for dealing with such errors upon import, depending upon how the transactions come in.

    As for setting the amount, that's a bit more tricky, but not too insanely difficult. In Moneydance each ParentTxn has a set of SplitTxns which specify the value. Most of the time there will be one split for each parent, but there can be more. The SplitTxns represent the "other side" of the transaction from the ParentTxn. So in your case you'd have to do something like the following in the loop. Please note I haven't run this myself yet, but I think it should be mostly correct.

    if txn.getParentTxn()==txn:  # this is the parent transaction  
      for splitIdx in [0..txn.getOtherTxnCount()-1]:
        split = txn.getOtherTxn(splitIdx)
        split.setAmount(split.getValue() * -1, 0, split.getParentAmount() * -1)
    else:  
        txn.setAmount(split.getValue() * -1, 0, split.getParentAmount() * -1)
    

    Thanks!

    Sean Reilly
    Developer, The Infinite Kind
    http://infinitekind.com

  2. 2 Posted by Elliot on 02 Feb, 2018 10:15 PM

    Elliot's Avatar

    Thanks so much Sean! That's really helpful. It's a downloaded and imported file from Lloyds's website. If there's a way to deal with this on import without all this code that would be even better

  3. 3 Posted by Elliot on 05 Mar, 2018 05:18 PM

    Elliot's Avatar

    Hi - any more ideas on this?

  4. Support Staff 4 Posted by Sean Reilly on 05 Mar, 2018 09:27 PM

    Sean Reilly's Avatar

    Hi Elliot,

    Ah yes, a few other people have reported the same problem. The code I sent earlier would work, but it should also be possible to write a python script that converted the values in the file as (or just before) it was imported.

    Can you tell me which file types are downloadable from the Lloyds web site? If there are multiple types, do they all have the same problem with the amounts?

    Thanks,

    Sean Reilly
    Developer, The Infinite Kind
    http://infinitekind.com

  5. 5 Posted by Elliot on 05 Mar, 2018 10:02 PM

    Elliot's Avatar

    Hey Sean,

    QIF, OFX, CSV - but issues with the whole lot. I've called up Lloyds to express my exasperation at this, but they insist they will not change the way they do things as they believe Credit Cards should import that way. It would be great if Moneydance had a feature to accommodate for this. I guess I could write a script that would find all the relevant tags in the QIF file and do this before import, but a feature within Monedance would be super convenient - especially if it already exists and I don't know about it!

  6. Support Staff 6 Posted by Sean Reilly on 06 Mar, 2018 11:37 AM

    Sean Reilly's Avatar

    Hi Elliot,

    Would it be possible to get a copy of one of the OFX files? With that it might be possible to detect that the file comes from Lloyds and have Moneydance handle it properly. There is also a formal specification for OFX files to which we could refer Lloyds in order to prove that their numbers are reversed.

    The problem with QIF is that there's no way to identify which bank it comes from, so we'd have to put a tick box in the interface somewhere. I'm not comfortable doing that because a non-negligible number of moneydance customers would accidentally select it and totally screw up their own imports.

    Thanks,
    Sean

  7. 7 Posted by Elliot on 25 Mar, 2018 05:08 PM

    Elliot's Avatar

    Hey Sean,

    I get the following error when trying to run your code:

    Error running script: Traceback (most recent call last):
      File "switchtransactions-LloydsCC.py", line 18, in <module>
        for splitIdx in [0..txn.getOtherTxnCount()-1]:
    AttributeError: 'float' object has no attribute 'txn'

  8. System closed this discussion on 24 Jun, 2018 05:10 PM.

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

Recent Discussions

14 Dec, 2024 08:26 PM
14 Dec, 2024 08:25 PM
14 Dec, 2024 08:22 PM
14 Dec, 2024 07:05 PM
14 Dec, 2024 06:35 PM