Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong multi-currency printing #465

Closed
rmoehn opened this issue Jan 10, 2017 · 11 comments
Closed

Wrong multi-currency printing #465

rmoehn opened this issue Jan 10, 2017 · 11 comments
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. print

Comments

@rmoehn
Copy link

rmoehn commented Jan 10, 2017

I'm not sure if I'm doing the right thing, but I think I've found a problem. I'm trying to use a currency trading account like this:

2017-01-07 buy food
    expenses:food   20 usd @ 1.30 cad
    assets:usd     -20 usd
    income:currency

hledger print yields:

2017/01/07 buy food
    expenses:food    20 usd @ 1.30 cad
    assets:usd                 -20 usd
                            -26.00 cad
    income:currency             20 usd

Using hledger print -O csv, I can understand how this is meant:

"txnidx","date","date2","status","code","description","comment","account","amount","commodity","credit","debit","status","posting-comment"
"1","2017/01/07","","","","buy food","","expenses:food","20 @ 1.30 cad","usd","","20 @ 1.30 cad","",""
"1","2017/01/07","","","","buy food","","assets:usd","-20","usd","20","","",""
"1","2017/01/07","","","","buy food","","income:currency","20","usd","","20","",""
"1","2017/01/07","","","","buy food","","income:currency","-26.00","cad","26.00","","",""

However, in this case print is not idempotent. – hledger print | hledger -f- print yields:

2017/01/07 buy food
    expenses:food    20 usd @ 1.30 cad
    assets:usd                 -20 usd
    -26.00 cad              -26.00 cad
    income:currency             20 usd

This looks wrong.

@simonmichael
Copy link
Owner

Thanks for the report. Yes, print's output is not always valid journal format, which is a pity. Postings where the amount is implicit can have a multi-commodity amount. To show this in valid journal format would mean showing one posting per commodity, like this:

2017-01-07 buy food
    expenses:food     20 usd @ 1.30 cad
    assets:usd       -20 usd
    income:currency   20 usd
    income:currency  -20 usd @ 1.30 cad

Should the print command do this ? Ie, show a journal entry which is not what you wrote, to get valid journal output ?

Or, it could just leave the amount implicit as it was in the first place ?

2017-01-07 buy food
    expenses:food     20 usd @ 1.30 cad
    assets:usd       -20 usd
    income:currency

It originally did this, but I had some reason to change it - clarity when troubleshooting ? See also #442 .

@simonmichael simonmichael added A-WISH Some kind of improvement request, hare-brained proposal, or plea. print labels Jan 10, 2017
@simonmichael
Copy link
Owner

Let's revert to the old behaviour and see what happens. I think this means print will show all entries with no explicit amount on the last posting - whether you wrote one in the journal entry or not. So eg if you did write all amounts explicitly:

2017-01-07 buy food
    expenses:food     20 usd @ 1.30 cad
    assets:usd       -20 usd
    income:currency   20 usd
    income:currency  -20 usd @ 1.30 cad

print will show

2017/01/07 buy food
    expenses:food     20 usd @ 1.30 cad
    assets:usd                  -20 usd
    income:currency              20 usd
    income:currency

Maybe this is ok. Maybe we'll need a --explicit option later.

simonmichael added a commit that referenced this issue Jan 10, 2017
This avoids printing invalid journal format for entries where an implicit amount has multiple commodities.
@simonmichael
Copy link
Owner

And I shouldn't have pushed that before updating tests. Oh well.

@simonmichael
Copy link
Owner

Also, as @ony pointed out this doesn't fix the problem. Eg we still have:

2017-01-07 buy food
    expenses:food   20 usd @ 1.30 cad
    assets:usd     -20 usd
    income:currency
    expenses:fee     3 usd
$ hledger -f 465.journal print
2017/01/07 buy food
    expenses:food    20 usd @ 1.30 cad
    assets:usd                 -20 usd
                            -26.00 cad
    income:currency             17 usd
    expenses:fee

Discussing a bit on IRC.

ony added a commit to ony/hledger that referenced this issue Jan 10, 2017
- Make output of print to be a valid journal
- Partially reverts 419f5f2

Fixes simonmichael#465
@rmoehn
Copy link
Author

rmoehn commented Jan 11, 2017

Thanks for the quick action!

For my purposes it would be enough if there was a canonical format that I can thread through multiple calls. Like hledger-rewrite -f … | hledger-rewrite -f- … | hledger-rewrite -f- … | hledger -f- print. I thought the CSV format would work, but apparently I misunderstood the purpose of CSV reading and writing. It's thought for communicating with outside programs, not for communicating with hledger itself, right?

@simonmichael
Copy link
Owner

Yeah. The CSV output of print has one record per posting, while we expect CSV input to have one record per transaction, so doing that with CSV sounds hard.

simonmichael pushed a commit that referenced this issue Jan 11, 2017
- Make output of print to be a valid journal
- Partially reverts 419f5f2

Fixes #465
@simonmichael
Copy link
Owner

Thanks for the PR! I believe this issue is now resolved in master.

@rmoehn
Copy link
Author

rmoehn commented Jan 11, 2017

Thanks! I will try it out soon.

@ony
Copy link
Collaborator

ony commented Jan 11, 2017

Though journal now is valid I've got strange output for journal

2016/1/1
    saving-card  $-105
    snacks  95 EUR @@ $100
    Equity:Unbalanced  ; absence of $5 here triggers strange behavior
2016/01/01
    saving-card                 $-105
    snacks             95 EUR @@ $100
    Equity:Unbalanced            $105    ; absence of $5 here triggers strange behavior
    Equity:Unbalanced           $-100    ; absence of $5 here triggers strange behavior

I would understand if the output would look like:

2016/01/01
    saving-card                           $-105
    snacks                       95 EUR @@ $100
    Equity:Unbalanced                      $105    ; absence of $5 here triggers strange behavior
    Equity:Unbalanced           -95 EUR @@ $100    ; absence of $5 here triggers strange behavior

@simonmichael
Copy link
Owner

I see, it looks like the balancing amount inferring function is missing an opportunity to combine same-commodity amounts. It's normal for the inferred balancing amount to be converted to the price's commodity ($) by the way, hledger always does that for similarity with Ledger/convenience reasons I don't fully recall.

ony added a commit to ony/hledger that referenced this issue Jan 11, 2017
This fixes issue exposed by a fix for simonmichael#465
simonmichael pushed a commit that referenced this issue Jan 11, 2017
This fixes issue exposed by a fix for #465
@rmoehn
Copy link
Author

rmoehn commented Jan 21, 2017

Looks like it works for me now! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-WISH Some kind of improvement request, hare-brained proposal, or plea. print
Projects
None yet
Development

No branches or pull requests

3 participants