lib: disallow prices in balance assertions/assignments (fix #824)
(and in Ledger-style {=FIXEDLOTPRICES} )
This commit is contained in:
parent
6f36702141
commit
86a91c514d
@ -721,7 +721,7 @@ priceamountp = option NoPrice $ do
|
|||||||
priceConstructor <- char '@' *> pure TotalPrice <|> pure UnitPrice
|
priceConstructor <- char '@' *> pure TotalPrice <|> pure UnitPrice
|
||||||
|
|
||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
priceAmount <- amountwithoutpricep <?> "amount (as a price)"
|
priceAmount <- amountwithoutpricep <?> "unpriced amount (specifying a price)"
|
||||||
|
|
||||||
pure $ priceConstructor priceAmount
|
pure $ priceConstructor priceAmount
|
||||||
|
|
||||||
@ -731,14 +731,17 @@ balanceassertionp = do
|
|||||||
char '='
|
char '='
|
||||||
exact <- optional $ try $ char '='
|
exact <- optional $ try $ char '='
|
||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
a <- amountp <?> "amount (for a balance assertion or assignment)" -- XXX should restrict to a simple amount
|
a <- amountwithoutpricep <?> "unpriced amount (for a balance assertion or assignment)"
|
||||||
return BalanceAssertion
|
return BalanceAssertion
|
||||||
{ baamount = a
|
{ baamount = a
|
||||||
, baexact = isJust exact
|
, baexact = isJust exact
|
||||||
, baposition = sourcepos
|
, baposition = sourcepos
|
||||||
}
|
}
|
||||||
|
|
||||||
-- http://ledger-cli.org/3.0/doc/ledger3.html#Fixing-Lot-Prices
|
-- Parse a Ledger-style fixed lot price: {=PRICE}
|
||||||
|
-- https://www.ledger-cli.org/3.0/doc/ledger3.html#Fixing-Lot-Prices .
|
||||||
|
-- Currently we ignore these (hledger's @ PRICE is equivalent),
|
||||||
|
-- and we don't parse a Ledger-style {PRICE} (equivalent to Ledger's @ PRICE).
|
||||||
fixedlotpricep :: JournalParser m (Maybe Amount)
|
fixedlotpricep :: JournalParser m (Maybe Amount)
|
||||||
fixedlotpricep = optional $ do
|
fixedlotpricep = optional $ do
|
||||||
try $ do
|
try $ do
|
||||||
@ -747,7 +750,7 @@ fixedlotpricep = optional $ do
|
|||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
char '='
|
char '='
|
||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
a <- amountp -- XXX should restrict to a simple amount
|
a <- amountwithoutpricep <?> "unpriced amount (for an ignored ledger-style fixed lot price)"
|
||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
char '}'
|
char '}'
|
||||||
return a
|
return a
|
||||||
|
|||||||
@ -436,6 +436,11 @@ One workaround is to isolate each commodity into its own subaccount:
|
|||||||
a:euro 0 == 1€
|
a:euro 0 == 1€
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Assertions and prices
|
||||||
|
|
||||||
|
Balance assertion (or assignment) amounts should not have a [price](#transaction-prices),
|
||||||
|
as the meaning of that would be unclear.
|
||||||
|
|
||||||
### Assertions and subaccounts
|
### Assertions and subaccounts
|
||||||
|
|
||||||
Balance assertions do not count the balance from subaccounts; they check
|
Balance assertions do not count the balance from subaccounts; they check
|
||||||
|
|||||||
@ -356,3 +356,12 @@ hledger -f - stats
|
|||||||
>>> /Transactions/
|
>>> /Transactions/
|
||||||
>>>2
|
>>>2
|
||||||
>>>=0
|
>>>=0
|
||||||
|
|
||||||
|
# 20. Balance assertions may not have a price in them.
|
||||||
|
hledger -f- stats
|
||||||
|
<<<
|
||||||
|
2019/01/01
|
||||||
|
(a) 1A = 1A @ 2B
|
||||||
|
>>>
|
||||||
|
>>>2 /unexpected '@'/
|
||||||
|
>>>=1
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user