InvestFields example of how to use

Bob B's Avatar

Bob B

29 May, 2020 03:18 AM

The documentation on how to use InvestFields is a bit weak :) I'm trying to figure out what all the fields are and how they are used, I've got the following but I'm only getting an empty BUY transaction in the register. What am I doing wrong?

CurrencyType security = book.getCurrencies().getCurrencyByName("Google");
ParentTxn ptTran = new ParentTxn(book);
ptTran.setAccount(parentAcct);

InvestFields f = new InvestFields();

  f.amount = 35000;
  f.date = 20200129;
  f.shares = 100;
  f.price = 3.50;
  f.txnType = InvestTxnType.BUY;
  f.secCurr = security;

  f.storeFields(ptTran);

   ptTran.syncItem();

  1. Support Staff 1 Posted by Sean Reilly on 29 May, 2020 09:00 AM

    Sean Reilly's Avatar

    Hi Bob,

    Yes, we really do need some documentation on InvestFields, and probably something else that wraps it, like an InvestmentTransactionBuilder.

    Can you try calling f.setFieldStatus(ptTran) before setting the other fields in f? Here's what I use in the investment transaction editor when saving the fields:

    InvestFields fields = new InvestFields();
    fields.setFieldStatus(txnType, txn); // you could use f.setFieldStatus(ptTxn) and .txnType = as you already are
    fields.date = dateField.getDate();
    fields.taxDate = showTaxDate ? taxDateField.getDate() : fields.date;
    fields.security = securityField.getSelectedAccount();
    fields.status = statusField.getStatus();
    fields.shares = fields.hasShares ? sharesField.getAmount() : 0;
    fields.price = priceField.getRawRate();
    fields.fee = fields.hasFee ? feeField.getAmount() : 0;
    fields.amount = amountField.getAmount();
    fields.payee = payeeField.getText();
    fields.feeAcct = feeAcctField.getSelectedAccount();
    fields.category = categoryField.getSelectedAccount();
    fields.xfrAcct = acctField.getSelectedAccount();
    fields.storeFields(ptxn);

    Can you let me know if any of that helps?

    Thanks,
    Sean

  2. 2 Posted by Bob B on 29 May, 2020 07:17 PM

    Bob B's Avatar

    Still only creating an empty buy tx with the correct date in the correct account. The numbers in brackets correspond to the number on the attached which is a manually entered transaction that I'm trying to create via an extension. I am able to create non-investment transactions in other accounts,

    CurrencyType security = book.getCurrencies().getCurrencyByName("Google");
    ParentTxn ptTran = new ParentTxn(book);
    ptTran.setAccount(parentAcct);

     InvestFields f = new InvestFields();

     (2) f.setFieldStatus(InvestTxnType.BUY,ptTran);

     (1) f.date = 20200129;
     (3) f.secCurr = security;
     (4) f.price = 3.50;
     (5) f.shares = 100;
     (6) f.amount = 35000;

         f.storeFields(ptTran);

       ptTran.syncItem();

  3. Support Staff 3 Posted by Sean Reilly on 29 May, 2020 09:18 PM

    Sean Reilly's Avatar

    One thing might be that the shares field should have a much higher number. I'm guessing that you mean that 100 shares were purchased. Because of how moneydance stores all amount values that should be multiplied by 10^x where x is the number of decimal places in the security CurrencyType object. If you have a floating point/double version of the amount you can call security.getLongValue(doubleValue) to get it. Or from a string, security.parse(stringValue, '.')

    Thanks,
    Sean

  4. 4 Posted by Bob B on 30 May, 2020 04:45 PM

    Bob B's Avatar

    Thanks but that didn't make any difference.

    I'm going to try to load the fields object from a manually entered tx. I haven't retrieved transactions yet so it will be a good learning experience. Are there any examples you can point me to?

    I'll try to compare the outputs with the inputs and see if I can find the issue.

    BTW: what does the InvestFields.debug bolean do?

  5. 5 Posted by Bob B on 30 May, 2020 05:20 PM

    Bob B's Avatar

    So I tried to display values using the sample python script (seemed like a quick easy way. I'm not familiar with python so I'm not sure i'm doing this correctly.

    f= InvestFields.setFieldsStatus(txn)
    print f.date

    I get the error:
    NameError: name 'InvestFields' is not defined

    I also tried
    f=InvestFields()

    same error

  6. 6 Posted by Bob B on 01 Jun, 2020 12:31 AM

    Bob B's Avatar

    I figured it out! I was using the field InvestFields.secCurr which is a currency not the InvestFields.security field which is an account.

    Now this begs the question, what is the best way to determine if the security is already in the account assuming that I have a security name like "Google" Is there a way to say 'add it if it's not already there'?

  7. Support Staff 7 Posted by Sean Reilly on 03 Jun, 2020 03:02 PM

    Sean Reilly's Avatar

    Nice work!

    You will need to ensure two things for any securities referenced by investment transactions:
     1) That a CurrencyType with Type==SECURITY for the security exists, and
     2) There is a sub-account of your investment account that has security as a currency and an account type of AccountType.SECURITY

    Thanks,
    Sean

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