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

balance assignments and posting dates causing wrong parsing #2025

Closed
ShrykeWindgrace opened this issue Apr 24, 2023 · 5 comments
Closed

balance assignments and posting dates causing wrong parsing #2025

ShrykeWindgrace opened this issue Apr 24, 2023 · 5 comments
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. journal The journal file format, and its features.

Comments

@ShrykeWindgrace
Copy link

I have the following journal with an autoposting rule:

= Expenses:Transport
    (Budget:Transport)  *-1


2023-01-01 Init
    Assets       367.45 EUR
    Init

2023-01-30 Amazon
    Assets       -257.59 EUR = 109.86 EUR  ; date: 2023-02-01
    Assets:Temp      257.59 EUR

2023-02-03 Ebay
    Assets               -30.25 EUR ; date: 2023-02-04
    Expenses:Gifts            29.95 EUR
    Expenses:Fees        0.30 EUR
    Assets               == 79.61 EUR

The hledger bal passes with flying colors, yet hledger bal --auto fails with

   | 2023-02-03 Ebay
   |     Assets              -30.25 EUR  ; date: 2023-02-04
   |     Expenses:Gifts       29.95 EUR
   |     Expenses:Fees         0.30 EUR
17 |     Assets                       0 == 79.61 EUR
   |                                    ^^^^^^^^^^^^

This balance assertion failed.
In account:    Assets
and commodity: EUR                             (no other commodities allowed)
this balance was asserted:     79.61
but the calculated balance is: 109.86
a difference of:               -30.25

even though there are no autopostings issued by the rewrite rule.

At the same time, if I delete the rule and keep only

2023-01-01 Init
    Assets       367.45 EUR
    Init

2023-01-30 Amazon
    Assets       -257.59 EUR = 109.86 EUR  ; date: 2023-02-01
    Assets:Temp      257.59 EUR

2023-02-03 Ebay
    Assets               -30.25 EUR ; date: 2023-02-04
    Expenses:Gifts            29.95 EUR
    Expenses:Fees        0.30 EUR
    Assets               == 79.61 EUR

both hledger bal and hledger bal --auto pass.

I am on

hledger 1.27.1, linux-x86_64

I'll try to test on a current master.

The output of

$ hledger reg 'Assets$' -I
2023-01-01 Init                              Assets                               367.45 EUR    367.45 EUR
2023-02-01 Amazon                            Assets                              -257.59 EUR    109.86 EUR
2023-02-03 Ebay                              Assets                                        0    109.86 EUR
2023-02-04                                   Assets                               -30.25 EUR     79.61 EUR

is identical to the output of hledger reg 'Assets$' --auto -I. I'd say that toggling --auto should not change the fail status of hledger bal.

@ShrykeWindgrace ShrykeWindgrace added the A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. label Apr 24, 2023
@simonmichael
Copy link
Owner

Good catch! I agree, that seems to be going wrong somehow.

@simonmichael simonmichael added journal The journal file format, and its features. needs:debugging To unblock: needs debugging/investigation labels Apr 24, 2023
@simonmichael
Copy link
Owner

Notes:

This transaction is balanced but the assertion fails, correctly because of the posting date:

2023-02-03
    Expenses    1
    Assets     -1        ; date: 2023-02-04
    Assets      0 = -1

But if we make the last amount implicit, both transaction balancing and the assertion succeed, which is wrong - one or the other should fail depending on what amount is inferred (I would expect -1):

2023-02-03
    Expenses    1
    Assets     -1        ; date: 2023-02-04
    Assets        = -1

If we add any auto posting rule and run with --auto, it fails again:

2023-02-03
    Expenses    1
    Assets     -1        ; date: 2023-02-04
    Assets        = -1

= an auto posting rule

@simonmichael simonmichael removed the needs:debugging To unblock: needs debugging/investigation label Apr 28, 2023
@simonmichael
Copy link
Owner

simonmichael commented Apr 28, 2023

Fixed: postings with balance assignments were being processed in parse order; now they are processed in posting date order.So now all three cases above fail, for the right reasons, regardless of --auto. Thanks for the report!

@simonmichael simonmichael changed the title Autoposting rules in a journal change order of balance assertions posting dates, balance assignments, and --auto causing wrong parsing Apr 28, 2023
@simonmichael simonmichael changed the title posting dates, balance assignments, and --auto causing wrong parsing balance assignments and posting dates causing wrong parsing Apr 28, 2023
@simonmichael
Copy link
Owner

Just for the record, I feel it's probably still possible to confuse it by having two transactions, each with multiple posting dates and assertions/assignments, which overlap each other's dates. I don't think that should be expected to work, as we process each transaction separately. But if someone wants to work up a test case, to see if the results are reasonable, that would be welcome.

@ShrykeWindgrace
Copy link
Author

Thanks for the prompt fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-BUG Something wrong, confusing or sub-standard in the software, docs, or user experience. journal The journal file format, and its features.
Projects
None yet
Development

No branches or pull requests

2 participants