Insert Transactions

percon's Avatar

percon

11 Sep, 2017 05:31 PM

I develop an extension, where I want to add transactions. But I do not find any clear resources on how to insert transactions into a certain account. I am not sure about the workflow of the transaction insertion what I do is the following:
ParentTxn ptx = new ParentTxn(book);
ptx.setAccount(account);
ptx.setDateInt(20170909);
ptx.setDescription("test");

SplitTxn stx = new SplitTxn(ptx);
stx.setDescription("test");
stx.setAccount(account);
long val = 500134;
stx.setAmount(val);
stx.negateAmount();

stx.setDirty();
ptx.setDirty();
stx.syncItem();
ptx.syncItem();
account.syncItem();
book.save();

The transaction gets saved but it does not contain the correct amount. I am not sure did I get it right with the parenttxn and splittxn. I tried some combinations but I do not really know how it works. I am also not sure about the syncing and saving. What I ultimately want is to do similar thing as text Import where the date, description and amount is inserted but the category is left empty. The documentation on such simple things as create, read, update and delete existing transactions is not very well documented or I did not find any good resource.

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