hledger add simplifies too much. Silently drops important information. #283

Closed
btittelbach opened this Issue Sep 12, 2015 · 8 comments

Projects

None yet

2 participants

@btittelbach

Hi,

I planned to do beverages inventory and cash-register calculation with hledger and playing around a bit with it seems that hledger-add does not handle commodites very well.

e.g. I tried using hledger add to add the following transaction:

2015/09/07 bought Mannerschnitten
    assets:current:cash:register        -23.88 EUR
    assets:current:inventory-edibles    48 Mannerschnitten @@ 23.88 EUR

but hledger simplifies and actually adds the following transaction to the journal:

    assets:current:cash:register        -23.88 EUR
    assets:current:inventory-edibles

This is clearly a bug where hledger unintentionally disposes of important information, i.e. the quantity of the commodity.

@simonmichael
Owner

I see what you mean:

$ hledger --version
hledger 0.26.98
$ hledger -f t.j add
...
Date [2015/09/12]: 
Description: 
Account 1: assets:current:cash:register
Amount  1: -23.88 EUR
Account 2: assets:current:inventory-edibles
Amount  2 [23.88 EUR]: 48 Mannerschnitten @@ 23.88 EUR
Account 3 (or . or enter to finish this transaction): 
2015/09/12
    assets:current:cash:register        -23.88 EUR
    assets:current:inventory-edibles  48 Mannerschnitten @@ 23.88 EUR

Save this transaction to the journal ? [y]: 
Saved.
Starting the next transaction (. or ctrl-D/ctrl-C to quit)
Date [2015/09/12]: 
$ cat t.j
; journal created 2015-09-12 by hledger

2015/09/12
    assets:current:cash:register        -23.88 EUR
    assets:current:inventory-edibles

The entry displayed is right but the one written to the file is not. Thanks for the report. I would welcome a patch.

@simonmichael simonmichael added this to the 0.27 milestone Sep 13, 2015
@btittelbach

mhhh, bit sleepy, already 03:06 here. Guess the simplest fix would be to check if
transaction is a conversion-transaction. i.e. if the transactions cost is balanced but the transactions commodities count is not.
If it is a conversion-transaction then don't elide it in postinsAsLines in Transaction.hs.

however, am not awake enough to write a patch right now, or to check if there is a much better solution. sorry

by conversion-transaction I mean any transaction of the type

2009/1/1
  assets:foreign currency   €100          ; one hundred euros
  assets:cash              $-135          ; exchanged for $135

as mentioned in http://hledger.org/manual.html#prices item #3. (which btw don't seem to work in hledger 0.26, possibly because of just this bug, need to investigate this further...)

@simonmichael
Owner

Works fine here..

@btittelbach

Sorry, you are right, they do work. I was referring to them not working as I intuitively expected them to work.

e.g. creating a journal with hledger add and inputing transactions this way:

Date [2015/09/14]: 
Description: test 12
Account 1: assets:cash
Amount  1: -20 EUR
Account 2: assets:inventory
Amount  2 [20.0 EUR]: 10 Mannerschnitten

and then manually adding a second conversion-transaction like in the manual, I get this journal:

2015/09/14 test 12
    assets:cash       -20 EUR @@ 10 Mannerschnitten
    assets:inventory

2015/09/14 test 12
    assets:cash       -40 EUR 
    assets:inventory  10 Mannerschnitten

Running hledger balance on that works perfectly.

             -60 EUR  
  20 Mannerschnitten  assets
             -60 EUR    cash
  20 Mannerschnitten    inventory
--------------------
             -60 EUR
  20 Mannerschnitten

until I run hledger balance --cost where I get

                    0  assets
 -20 Mannerschnitten    cash
  20 Mannerschnitten    inventory
--------------------
                   0

Because what I really expected to get was:

% hledger balance       
             -60 EUR  
  20 Mannerschnitten  assets
             -60 EUR    cash
  20 Mannerschnitten    inventory
--------------------
             -60 EUR
  20 Mannerschnitten


% hledger balance --cost
                   0  assets
             -60 EUR    cash
              60 EUR    inventory
--------------------
                   0

which is what I get with a journal that was manually created to look like this:

2015/09/14 test 12
    assets:cash       -20 EUR
    assets:inventory  10 Mannerschnitten @@ 20 EUR

2015/09/14 test 12
    assets:cash       -40 EUR 
    assets:inventory  10 Mannerschnitten @@ 40 EUR
@simonmichael
Owner

That makes sense ? In your first example, the amounts are priced in Mannerschnitten so balance --cost reports in that commodity. In your second example, they are priced in EUR so balance --cost reports in that.

@btittelbach

exactly, I want the functionality of the second example but I can get that only if I manually edit the journal.

If I have a commodity priced in a currency, I expect balance to show the amount of commodities and balance --cost to show the cost in said currency of those commodities.

That only works, if I manually create the ledger file so that the account I'm querying contains postings of the form
assets:inventory 10 Mannerschnitten @@ 40 EUR

If I use hledger add as in the first of above examples, suddenly Euros are priced as Mannerschnitten, which is strange (but not incorrect). Though in assets:cash I would not care, since it's about cash and balance already outputs the EUR prices I want.

In assets:inventory however, I want to be able to query the balance of each commodity as well as their total --cost. This is where the missing information prevents me from doing that.


In the first place, I find it strange that hledger balance --cost behaves completely different depending on whether a transaction is written as

2015/09/14 test 12
    assets:cash       -20 EUR 
    assets:inventory  10 Mannerschnitten

or as

2015/09/14 test 12
    assets:cash       -20 EUR @@ 10 Mannerschnitten
    assets:inventory  10 Mannerschnitten @@ 20 EUR

as in theory, they should contain the same information.


Obviously this might be a special case and thus I'm not sure what the best solution here is.
Naively, reversing commodity and currency depending on the posting/account in the transaction, could work... e.g.:

Maybe ?? hledger should exchange the the MixedAmount Types and treat an entry

2015/09/14 test 12
    assets:cash       -20 EUR @@ 10 Mannerschnitten
    assets:inventory

as if it was written

2015/09/14 test 12
    assets:cash       -20 EUR @@ 10 Mannerschnitten
    assets:inventory  10 Mannerschnitten @@ 20 EUR

Or Maybe: hledger add should out of the box write

2015/09/14 test 12
    assets:cash       -20 EUR
    assets:inventory  10 Mannerschnitten @@ 20 EUR

(or maybe I'm thinking about this all wrong and you have a good suggestion that would point me in a better direction)

@simonmichael
Owner

This is a bit more than I can absorb right now - it might be good to chat about this in real time on IRC ?

Now I've looked up Mannerschnitten, I see why you don't want that to be the price's currency. Also I see you're using "commodity" and "currency" to distinguish these concepts. Note I'm used to treating these as interchangeable synonyms, and hledger treats them as the same thing.

In a transaction with implicit conversion (ie prices examples case 3), it assumes the second posting's amount is the price. If you enter the postings in the reverse order during hledger add, does it do what you want ?

@simonmichael
Owner

I think this commit and my earlier suggestion resolves everything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment