fix: failing balance assertions with cost show correct highlight #2083
This commit is contained in:
parent
4a2da0ba1b
commit
1ef48fd7a5
@ -504,7 +504,8 @@ journalBalanceTransactions bopts' j' =
|
|||||||
-- This stores the balanced transactions in case 2 but not in case 1.
|
-- This stores the balanced transactions in case 2 but not in case 1.
|
||||||
balanceTransactionAndCheckAssertionsB :: Either Posting Transaction -> Balancing s ()
|
balanceTransactionAndCheckAssertionsB :: Either Posting Transaction -> Balancing s ()
|
||||||
balanceTransactionAndCheckAssertionsB (Left p@Posting{}) =
|
balanceTransactionAndCheckAssertionsB (Left p@Posting{}) =
|
||||||
-- update the account's running balance and check the balance assertion if any
|
-- Update the account's running balance and check the balance assertion if any.
|
||||||
|
-- Note, cost is ignored when checking balance assertions, currently.
|
||||||
void . addAmountAndCheckAssertionB $ postingStripPrices p
|
void . addAmountAndCheckAssertionB $ postingStripPrices p
|
||||||
balanceTransactionAndCheckAssertionsB (Right t@Transaction{tpostings=ps}) = do
|
balanceTransactionAndCheckAssertionsB (Right t@Transaction{tpostings=ps}) = do
|
||||||
-- make sure we can handle the balance assignments
|
-- make sure we can handle the balance assignments
|
||||||
|
|||||||
@ -21,6 +21,7 @@ import Data.Text (Text)
|
|||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
|
||||||
import Hledger.Data.Transaction (showTransaction)
|
import Hledger.Data.Transaction (showTransaction)
|
||||||
|
import Hledger.Data.Posting (postingStripPrices)
|
||||||
import Hledger.Data.Types
|
import Hledger.Data.Types
|
||||||
import Hledger.Utils
|
import Hledger.Utils
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
@ -118,7 +119,9 @@ makePostingErrorExcerpt p findpostingerrorcolumns =
|
|||||||
Just t -> (f, errabsline, merrcols, ex)
|
Just t -> (f, errabsline, merrcols, ex)
|
||||||
where
|
where
|
||||||
(SourcePos f tl _) = fst $ tsourcepos t
|
(SourcePos f tl _) = fst $ tsourcepos t
|
||||||
mpindex = transactionFindPostingIndex (==p) t
|
-- p had cost removed in balanceTransactionAndCheckAssertionsB,
|
||||||
|
-- must remove them from t's postings too (#2083)
|
||||||
|
mpindex = transactionFindPostingIndex ((==p).postingStripPrices) t
|
||||||
errrelline = case mpindex of
|
errrelline = case mpindex of
|
||||||
Nothing -> 0
|
Nothing -> 0
|
||||||
Just pindex ->
|
Just pindex ->
|
||||||
|
|||||||
@ -336,19 +336,33 @@ $ hledger -f - stats
|
|||||||
> /Transactions/
|
> /Transactions/
|
||||||
>=0
|
>=0
|
||||||
|
|
||||||
# 19. Balance assertions may have a price, but it's ignored
|
# 19. Cost is ignored when checking balance assertions.
|
||||||
<
|
<
|
||||||
2019/01/01
|
2023-01-01
|
||||||
|
(a) 1A @ 1B = 1A
|
||||||
|
|
||||||
|
$ hledger -f- check
|
||||||
|
|
||||||
|
# 20. The asserted balance may have a cost, also ignored
|
||||||
|
<
|
||||||
|
2023-01-01
|
||||||
(a) 1A @ 1B = 1A @ 2B
|
(a) 1A @ 1B = 1A @ 2B
|
||||||
|
|
||||||
$ hledger -f- print
|
$ hledger -f- check
|
||||||
>
|
|
||||||
2019-01-01
|
|
||||||
(a) 1A @ 1B = 1A @ 2B
|
|
||||||
|
|
||||||
>=0
|
# 21. A cost does not disrupt highlighting in the balance assertion error message.
|
||||||
|
<
|
||||||
|
2023-01-01
|
||||||
|
(a) 1A @ 1B = 5A
|
||||||
|
|
||||||
# 20. Balance assignments may have a price, and it's used for the posting amount.
|
$ hledger -f- check
|
||||||
|
>2 /
|
||||||
|
2 \| \(a\) 1A @ 1B = 5A
|
||||||
|
\| \^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^\^
|
||||||
|
/
|
||||||
|
>=1
|
||||||
|
|
||||||
|
# 22. Balance assignments may have a cost, and it's used for the posting amount.
|
||||||
<
|
<
|
||||||
2019/01/01
|
2019/01/01
|
||||||
(a) = 1A @ 2B
|
(a) = 1A @ 2B
|
||||||
@ -360,7 +374,7 @@ $ hledger -f- print --explicit
|
|||||||
|
|
||||||
>=0
|
>=0
|
||||||
|
|
||||||
# 21. The exact amounts are compared; display precision does not affect assertions.
|
# 23. The exact amounts are compared; display precision does not affect assertions.
|
||||||
<
|
<
|
||||||
commodity $1000.00
|
commodity $1000.00
|
||||||
|
|
||||||
@ -374,7 +388,7 @@ $ hledger -f- print
|
|||||||
> /2019/
|
> /2019/
|
||||||
>=0
|
>=0
|
||||||
|
|
||||||
# 22. This fails
|
# 24. This fails
|
||||||
<
|
<
|
||||||
commodity $1000.00
|
commodity $1000.00
|
||||||
|
|
||||||
@ -388,7 +402,7 @@ $ hledger -f- print
|
|||||||
>2 /a difference of.*0\.004/
|
>2 /a difference of.*0\.004/
|
||||||
>=1
|
>=1
|
||||||
|
|
||||||
# 23. This fails
|
# 25. This fails
|
||||||
<
|
<
|
||||||
commodity $1000.00
|
commodity $1000.00
|
||||||
|
|
||||||
@ -402,7 +416,7 @@ $ hledger -f- print
|
|||||||
>2 /a difference of.*0\.0001/
|
>2 /a difference of.*0\.0001/
|
||||||
>=1
|
>=1
|
||||||
|
|
||||||
# 24. Inclusive assertions include balances from subaccounts.
|
# 26. Inclusive assertions include balances from subaccounts.
|
||||||
<
|
<
|
||||||
2019/1/1
|
2019/1/1
|
||||||
(a) X1
|
(a) X1
|
||||||
@ -426,7 +440,7 @@ $ hledger -f- print
|
|||||||
|
|
||||||
>=0
|
>=0
|
||||||
|
|
||||||
# 25. Inclusive balance assignments also work (#1207).
|
# 27. Inclusive balance assignments also work (#1207).
|
||||||
<
|
<
|
||||||
2020-01-25
|
2020-01-25
|
||||||
(a:aa) 1
|
(a:aa) 1
|
||||||
@ -456,7 +470,7 @@ $ hledger -f- print -x
|
|||||||
|
|
||||||
>=0
|
>=0
|
||||||
|
|
||||||
# 26. When balance assignment with a cost generates two postings in one commodity,
|
# 28. When balance assignment with a cost generates two postings in one commodity,
|
||||||
# the balance assertion appears only on the last, not both. (#1965)
|
# the balance assertion appears only on the last, not both. (#1965)
|
||||||
<
|
<
|
||||||
2022-01-01
|
2022-01-01
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user