Sean Reilly on 06 Dec, 2019 11:50 AM
The best way to record, or edit, investment transactions is to use the InvestFields class. Create a new InvestFields object and set the various properties on it, or use the setFieldStatus(Txn) method with an existing transaction from the investment account. Once you've got the right properties into the InvestFields class then use the storeFields(Txn) method for it to apply the changes to the transaction you gave it, which could just be a new blank ParentTxn.
Sean Reilly on 07 Dec, 2019 05:04 PM
Yes, storeFields(Txn) will automatically create the appropriate splits if they're not already in the transaction. Can you paste the NPE stack trace? You will need to make sure any required fields are there... I guess I don't have a helpful validator on it yet.
Hi Sean, I found my error. I have one last point. When I have transactions that are against the Investment Account rather than a Security (e.g. interest, management fee) I use the InvestTxnType.BANK and set the following fields:
Amount (positive for income, negative for expense)
Category (Interest or Management Fee)
This creates the transactions but with a zero amount. Further testing and I changed 'category' and 'hasCategory' to 'xfrAcct' and 'has xfrAcct' it worked. I suppose using xfr as the transaction type would infer using the xfrAcct, however, the 'transfer' is to a category. Adding two new transaction types of 'Investment Income' and 'Investment Expense' would help.