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.

  1. System closed this discussion on 11 Dec, 2017 05:40 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