tag:infinitekind.tenderapp.com,2009-01-14:/discussions/moneydance-development/5834-txn-categoriesInfinite Kind: Discussion 2021-09-10T18:20:21Ztag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-05-20T07:18:33Z2021-05-20T07:18:33ZTxn categories<div><p>.getAccount() is the method to call. It’s inherited from AbstractTxn</p>
<p>Have you looked at the api doc?<br>
<a href="https://infinitekind.com/dev/apidoc/index.html">https://infinitekind.com/dev/apidoc/index.html</a></p>
<p>From parent. Get split count. Iterate each split. Get the category (Account)<br>
Perhaps take a look at my extract data extension for extract account registers. It will show you how to navigate the txns and get data.</p>
<p><a href="https://infinitekind.com/dev/apidoc/index.html">https://infinitekind.com/dev/apidoc/index.html</a></p>
<p>?</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-05-20T07:38:10Z2021-05-20T07:38:10ZTxn categories<div><p>FYI - this is the repr() code on ParentTxn and SplitTxn:</p>
<pre>
<code>PARENT
StringBuffer sb = new StringBuffer("[ParentTxn(" + this.syncID + ") ");
sb.append(getDateInt()).append(' ');
sb.append("desc=");
sb.append(getDescription());
sb.append("; ");
sb.append("val=");
sb.append(getValue());
sb.append("; ");
sb.append("stat=");
sb.append(getStatusChar());
sb.append("; ");
sb.append("#splits=");
sb.append(getSplitCount());
sb.append("; ");
sb.append("chk=");
sb.append(getCheckNumber());
sb.append("; ");
sb.append("acct=");
sb.append(getAccount());
sb.append("; ");
if (isDirty())
sb.append("dirty; ");
sb.append("splits=");
for (int i = 0; i < getSplitCount(); i++) {
sb.append(getSplit(i));
sb.append(", ");
}
sb.append("; ]");
return sb.toString();
SPLIT
StringBuffer sb = new StringBuffer("SplitTxn: ");
sb.append("val=");
sb.append(getValue());
sb.append("; ");
sb.append("amt=");
sb.append(getParentAmount());
sb.append("; ");
sb.append("desc=");
sb.append(getDescription());
sb.append("; ");
sb.append("stat=");
sb.append(getStatusChar());
sb.append("; ");
sb.append("cat=");
sb.append(getAccount());
sb.append("; ");
if (getTags() != null) {
SyncRecord syncRecord = getTags();
sb.append("tags=[");
for (String key : syncRecord.keySet())
sb.append("(" + key + ":" + (String)syncRecord.get(key) + ")");
sb.append("];");
}
if (isDirty())
sb.append("dirty; ");
sb.append(" ]");
return sb.toString();</code>
</pre></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-05-21T04:00:30Z2021-05-21T04:00:33ZTxn categories<div><p>Thanks, Stuart, I've already been looking at your export_data code to figure out how to read/write local files from Python, but haven't read all parts of that code as yet.</p>
<p>I saw you recommended using some beta version of Moneydance for Python work, but as a brand new user, I figured I'd stick with the release version until I encounter an issue.... don't want to encounter beta version bugs while I'm still learning.</p>
<p>Where do you find the repr code quoted above? Is the moneydance Python code available to view?</p>
<p>I got to wondering after I posted if maybe "cat" was obtained from the SplitTxn. But in this account I'm looking at, there are two types of transactions.</p>
<p>Some identify as SplitTxn, and the repr's cat= the account name in which I find the transaction. But in the register for that account, the Category is listed as the account containing the ParentTxn. So that is a bit inconsistent.</p>
<p>The other type of transaction identifies as a ParentTxn, and shows no cat= in the repr. But there is a "real" Category (not an account) listed in the Category field in the register.</p>
<p>So I guess what I'd like to obtain is the value that is in the Category field in the register: how do I get that? So I speculate that for SplitTxn, I could go look inside the associated ParentTxn, and obtain getAccount from it?</p>
<p>For the ParentTxn items, if #splits==1, maybe the same thing works? Would getAccount return the "category account name" in that case?</p>
<p>When there are more splits, of course there would be more categories or accounts.</p>
<p>Although I don't have any category names that are the same as account names, is that possible, and how would they be distinguished? The category list is distinct from the account list in the Tools menu, but they are listed together in the dropdown for choosing a category in the register (with different icons, I see).</p></div>v+iktag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-05-21T04:24:03Z2021-05-21T04:24:04ZTxn categories<div><p>Looking at SplitTxn, I see getParentTxn, getFlipSide, and getOtherTxn. These are not obvious by name alone, or by the brief description with them, which is mostly redundant with the names. The first seems to be most obvious, and probably what I want for the above.</p>
<p>Since there is also a getOtherTxnCount, I might guess that this is a way to get to the other splits of the same ParentTxn? Not obvious if this SplitTxn is or is not in such a list, although "other" implies not.</p>
<p>Not at all sure what the FlipSide is all about.</p>
<p>Looking at ParentTxn, the getSplitCount and getSplit seem obvious, until one also finds getOtherCount and getOtherTxn, and then also a getParentTxn !</p></div>v+iktag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-05-21T08:22:44Z2021-05-21T08:22:44ZTxn categories<div><p>A few responses:</p>
<ul>
<li>
<p>Unless you are writing or running Python extensions, then you don't need the latest MD version... However, as a new user, I would recommend you install the latest preview version (it will soon become the latest released version)</p>
</li>
<li>
<p>Categories do not exist.. They are accounts. use .getAccountType() and check for 'INCOME' or 'EXPENSE' for a category.</p>
</li>
<li>
<p>It depends on how you are getting your TxnSet, but in essence you need to check for txn being a Parent 'if isinstance(txn, ParentTxn) then'</p>
</li>
<li>
<p>If you find a split, then it's a transfer in/out of the account initiated elsewhere.</p>
</li>
<li>
<p>To navigate the parents, you use i=txn.getOtherTxnCount() and iterate txn.getOtherTxn(i) to get its splits.</p>
</li>
<li>
<p>.getParent() gets you back to the Parent from a split.</p>
</li>
</ul>
<p>This attached code may help you?</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-05-22T04:17:27Z2021-05-22T04:17:29ZTxn categories<div><p>Yes, helpful info again. So far I'm just writing a Pyithon script. May want to figure out how to run it from an extension as you describe somewhere. For now, the Console suffices for development and probably even for use, since it will be once a week.</p>
<p>Was surprised that "name of account" != Txn.getAccount() because the types don't compare, but puzzled that out.</p>
<p>Got the values shown in the register in the "Category" field, so that was progress.</p>
<p>Now to do some plain Python coding to finish the project. But I have all the parts.</p>
<p>There is a jython 3.x these days, wonder if Moneydance will offer that as an option. 2.x is fully end of life.</p></div>v+iktag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-05-22T05:18:40Z2021-05-22T05:18:40ZTxn categories<div><p>txn.getAccount() returns an Account object. It will never be the ‘name’. If you ‘print txn.getAccount()’ then you get the short account name. What you are actually doing is calling ‘repr(txn.getAccount())’ which is then calling .getAccountName().</p>
<p>As mentioned, txn.getAccount() on the parent is the ‘account’ that the txn is located and thesplit.getAccount() will be the acct/cat.</p>
<p>FYI - you are NOT using Python. You are using Jython. This is Java based. The very latest is 2.7. There is no 3.x. Sorry.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-05-22T17:45:50Z2021-05-22T17:45:51ZTxn categories<div><p>Spotted jython3 on github, but reading further in that repository and the jython repository makes it clear that there is no released jython 3, sadly. Ah well, jython 2.7 is better to code with than Java itself.</p>
<p>I was just hoping, I guess, since when I started using Python, it was right at the time Python 3 was coming out, and I never really learned Python 2... but for simple things like I'm doing here, it will be fine.</p></div>v+iktag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-05-22T17:50:10Z2021-05-22T17:50:10ZTxn categories<div><p>I’m sure Jython 2.7 can do everything that Python 3.x can do.</p></div>Stuart Beesley (Mr Toolbox)tag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-06-11T06:24:35Z2021-06-11T09:49:10ZTxn categories<div><p>Just a few syntax differences between Py 2 & 3 for this sort of stuff, mostly the print function, and the / operator works different for int.</p>
<p>Got my loan interest calculations all worked out. Discovered Quicken had been calculating one of them wrong for the last 9 years... I couldn't figure out what error they were making from the variation in calculations: sometimes it was too much interest, other times too little, but too much predominated. Oh well, my Python code compares well to other amortization calculators, and Quicken's doesn't, so I think mine is correct, and glad to find that error and get it corrected before the loan matured. [For interested parties, the loan with errors was compounded daily; monthly compounding works correctly in Q, but not daily, AFAICT].</p></div>v+iktag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-06-11T10:21:28Z2021-06-11T10:21:28ZTxn categories<div><p>I'm heartened to see some progress on Jython 3. I think of the differences between 2 and 3 as relatively minor, but it's nice to see a path ahead.</p>
<p>Don't get me started about loan calculations. We have them built into moneydance (have you tried the Loan Calculator?) but there are so many different ways to calculate interest!</p>
<p>Thanks,<br>
Sean</p></div>Sean Reillytag:infinitekind.tenderapp.com,2009-01-14:Comment/492062872021-06-11T18:15:59Z2021-06-11T18:15:59ZTxn categories<div><p>And I'm heartened to hear that you are observing progress on Jython 3. While I agree that for most types of calculations I would expect to add to Moneydance, the differences are minor, it would be nice to dispose of Python 2 syntax since the rest of the Python environments have moved on to Python 3.</p>
<p>So the Loans I am dealing with are loans I have made to others, and folks here in the forums indicated (as did my reading of documentation) that the Loan Accounts are set up for loans I owe. If the Loan Calculator is separate from Loan Accounts, I overlooked it, and will search the documentation some more, but suspect it is unlikely to deal with loans to others, or someone would have mentioned it when I inquired about how to deal with setting up an account for loans to other.s. While the necessary Jython to do the work was straightforward, I haven't attempted to streamline the calculations into an extension, but just run them from the console. I only implemented the two types of loan calculations that I need, whereas if I had gone to the effort of implementing more of them, it would be more worthwhile to figure out the extension packaging stuff.</p>
<p>Indeed, there are a large number of loan interest calculation techniques, from 360 day years, to 365/366 day years, to monthly calculations, beginning balance for a period, average daily balance, simple versus compound interest, etc. And many types of loan terms, single draw, multiple draw, revolving loan, etc. There are more, probably including some I've not heard of yet!</p></div>v+ik