Delete an Account Using the Python Interpreter...

goforit1's Avatar

goforit1

08 May, 2019 05:24 PM

I want to use the MnoeyBot Console to run a Python Snippet to delete an Investment account called IBM. After reading this discussion:

https://infinitekind.tenderapp.com/discussions/moneydance-development/1851-delete-an-account

I tried to run this snippet:

moneydance.getUI().deleteAccountAndAllReferences(IBM)

It produces the following error:

File "<string>", line 1, in <module>
NameError: name 'IBM' is not defined

I am relatively new to Python but have a programming background. What am I doing wrong? Thank you.

  1. 1 Posted by hleofxquotes on 08 May, 2019 05:49 PM

    hleofxquotes's Avatar

    NameError: name 'IBM' is not defined

    You need to quote as in 'IBM'

  2. 2 Posted by goforit1 on 08 May, 2019 07:00 PM

    goforit1's Avatar

    hleofxquotes,

    Thank you for your prompt response. I tried the command

    moneydance.getUI().deleteAccountAndAllReferences('IBM')

    as suggested. That produced a different error:

    File "<string>", line 1, in <module>
    TypeError: deleteAccountAndAllReferences(): 1st arg can't be coerced to com.infinitekind.moneydance.model.Account

    Any other suggestions would be appreciated.

  3. 3 Posted by hleofxquotes on 08 May, 2019 08:08 PM

    hleofxquotes's Avatar

    Ah .. the method deleteAccountAndAllReferences() need an Account and not just a String.

    You will need to create an instance of Account. Perhaps by iterating through the list of accounts.

  4. 4 Posted by goforit1 on 08 May, 2019 08:13 PM

    goforit1's Avatar

    hleofxquotes,

    Unfortunately, I don't know how to create an instance of an Account. Would you mind telling me how to do that? My goal is to delete a number of accounts programatically instead of one at a time as Moneydance requires you to do. Thanks.

  5. System closed this discussion on 07 Aug, 2019 08:20 PM.

  6. goforit1 re-opened this discussion on 11 Nov, 2019 01:33 PM

  7. 5 Posted by goforit1 on 11 Nov, 2019 01:34 PM

    goforit1's Avatar

    Is there anyone who can help me with this?

  8. 6 Posted by hleofxquotes on 11 Nov, 2019 04:49 PM

    hleofxquotes's Avatar

    Unfortunately, I don't know how to create an instance of an Account.

    For existing account, you can iterate through a list of acount with something like this

    # print a list of accounts
    
    from com.infinitekind.moneydance.model import AccountUtil  
    book = moneydance.getCurrentAccountBook()  
    for acct in AccountUtil.getAccountIterator(book):  
      print acct
    

    See: https://bitbucket.org/hleofxquotesteam/md-dev-scripts/src/master/pr...

  9. 7 Posted by goforit1 on 12 Nov, 2019 11:10 AM

    goforit1's Avatar

    I got the listing of accounts using this:

    from com.infinitekind.moneydance.model import AccountUtil
    book = moneydance.getCurrentAccountBook()
    acct = None
    for acct in AccountUtil.getAccountIterator(book):

    I then added the line to delete the account:

    moneydance.getUI().deleteAccountAndAllReferences(IBM)

    It produced the following error: (Same as before.)

    File "<string>", line 5, in <module>
    NameError: name 'IBM' is not defined

    I'm not sure I got any closer. Is there anyone who can help?

  10. 8 Posted by goforit1 on 12 Nov, 2019 03:07 PM

    goforit1's Avatar

    I tried this:

    moneydance.getUI().deleteAccountAndAllReferences('IBM')

    as referenced in this post:

    https://infinitekind.tenderapp.com/discussions/moneydance-development/1851-delete-an-account

    When I run that, I get this:

    Beginning snippet at Tue Nov 12 09:59:34 EST 2019
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
    TypeError: deleteAccountAndAllReferences(): 1st arg can't be coerced to com.infinitekind.moneydance.model.Account

    Can anyone help?

  11. 9 Posted by hleofxquotes on 13 Nov, 2019 01:53 AM

    hleofxquotes's Avatar

    (Not tested) you can try something like this

    ...
    # find the acccount
    account = rootAccount.getAccountByName('IBM')  
    # pass the account object to deleteAccountAndAllReferences
    moneydance.getUI().deleteAccountAndAllReferences(account)
    
  12. 10 Posted by goforit1 on 13 Nov, 2019 10:07 AM

    goforit1's Avatar

    I really appreciate you trying to help. It didn't work. Here is the code I ran:

    from com.infinitekind.moneydance.model import AccountUtil
    book = moneydance.getCurrentAccountBook()
    acct = None
    for acct in AccountUtil.getAccountIterator(book)
    account = rootAccount.getAccountByName('IBM')
    moneydance.getUI().deleteAccountAndAllReferences(account)

    Here is the reply:

    Beginning snippet at Wed Nov 13 05:03:38 EST 2019
      File "<string>", line 4
        for acct in AccountUtil.getAccountIterator(book)
                                                       ^
    SyntaxError: mismatched input '\n' expecting COLON

    Any suggestions?

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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