Txn categories

v+ik's Avatar

v+ik

20 May, 2021 05:24 AM

The Python "repr" for a ParentTxn and for a SplitTxn includes a "cat" field, but I can't figure out what API to call to obtain it... surely there is one? But I can't find it in Txn, AbstractTxn, ParentTxn, or SplitTxn.

Help!

  1. 1 Posted by Stuart Beesley ... on 20 May, 2021 07:18 AM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    .getAccount() is the method to call. It’s inherited from AbstractTxn

    Have you looked at the api doc?
    https://infinitekind.com/dev/apidoc/index.html

    From parent. Get split count. Iterate each split. Get the category (Account)
    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.

    https://infinitekind.com/dev/apidoc/index.html

    ?

  2. 2 Posted by Stuart Beesley ... on 20 May, 2021 07:38 AM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    FYI - this is the repr() code on ParentTxn and SplitTxn:

    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();
    
  3. 3 Posted by v+ik on 21 May, 2021 04:00 AM

    v+ik's Avatar

    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.

    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.

    Where do you find the repr code quoted above? Is the moneydance Python code available to view?

    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.

    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.

    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.

    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?

    For the ParentTxn items, if #splits==1, maybe the same thing works? Would getAccount return the "category account name" in that case?

    When there are more splits, of course there would be more categories or accounts.

    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).

  4. 4 Posted by v+ik on 21 May, 2021 04:24 AM

    v+ik's Avatar

    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.

    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.

    Not at all sure what the FlipSide is all about.

    Looking at ParentTxn, the getSplitCount and getSplit seem obvious, until one also finds getOtherCount and getOtherTxn, and then also a getParentTxn !

  5. 5 Posted by Stuart Beesley ... on 21 May, 2021 08:22 AM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    A few responses:

    • 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)

    • Categories do not exist.. They are accounts. use .getAccountType() and check for 'INCOME' or 'EXPENSE' for a category.

    • 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'

    • If you find a split, then it's a transfer in/out of the account initiated elsewhere.

    • To navigate the parents, you use i=txn.getOtherTxnCount() and iterate txn.getOtherTxn(i) to get its splits.

    • .getParent() gets you back to the Parent from a split.

    This attached code may help you?

  6. 6 Posted by v+ik on 22 May, 2021 04:17 AM

    v+ik's Avatar

    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.

    Was surprised that "name of account" != Txn.getAccount() because the types don't compare, but puzzled that out.

    Got the values shown in the register in the "Category" field, so that was progress.

    Now to do some plain Python coding to finish the project. But I have all the parts.

    There is a jython 3.x these days, wonder if Moneydance will offer that as an option. 2.x is fully end of life.

  7. 7 Posted by Stuart Beesley ... on 22 May, 2021 05:18 AM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    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().

    As mentioned, txn.getAccount() on the parent is the ‘account’ that the txn is located and thesplit.getAccount() will be the acct/cat.

    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.

  8. 8 Posted by v+ik on 22 May, 2021 05:45 PM

    v+ik's Avatar

    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.

    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.

  9. 9 Posted by Stuart Beesley ... on 22 May, 2021 05:50 PM

    Stuart Beesley - JUST A FELLOW USER and Toolbox ‘guy’'s Avatar

    I’m sure Jython 2.7 can do everything that Python 3.x can do.

  10. 10 Posted by v+ik on 11 Jun, 2021 06:24 AM

    v+ik's Avatar

    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.

    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].

  11. Support Staff 11 Posted by Sean Reilly on 11 Jun, 2021 10:21 AM

    Sean Reilly's Avatar

    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.

    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!

    Thanks,
    Sean

  12. 12 Posted by v+ik on 11 Jun, 2021 06:15 PM

    v+ik's Avatar

    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.

    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.

    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!

  13. System closed this discussion on 10 Sep, 2021 06:20 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