journal: also parse Ledger-style "virtual posting costs" - (@), (@@)
This commit is contained in:
parent
847f924828
commit
3ad2e50ec5
@ -735,15 +735,17 @@ simplecommoditysymbolp :: TextParser m CommoditySymbol
|
|||||||
simplecommoditysymbolp = takeWhile1P Nothing (not . isNonsimpleCommodityChar)
|
simplecommoditysymbolp = takeWhile1P Nothing (not . isNonsimpleCommodityChar)
|
||||||
|
|
||||||
priceamountp :: JournalParser m AmountPrice
|
priceamountp :: JournalParser m AmountPrice
|
||||||
priceamountp = (do
|
priceamountp = label "transaction price" $ do
|
||||||
|
-- https://www.ledger-cli.org/3.0/doc/ledger3.html#Virtual-posting-costs
|
||||||
|
parenthesised <- option False $ char '(' >> pure True
|
||||||
char '@'
|
char '@'
|
||||||
priceConstructor <- char '@' *> pure TotalPrice <|> pure UnitPrice
|
priceConstructor <- char '@' *> pure TotalPrice <|> pure UnitPrice
|
||||||
|
when parenthesised $ void $ char ')'
|
||||||
|
|
||||||
lift (skipMany spacenonewline)
|
lift (skipMany spacenonewline)
|
||||||
priceAmount <- amountwithoutpricep -- <?> "unpriced amount (specifying a price)"
|
priceAmount <- amountwithoutpricep -- <?> "unpriced amount (specifying a price)"
|
||||||
|
|
||||||
pure $ priceConstructor priceAmount
|
pure $ priceConstructor priceAmount
|
||||||
) <?> "price amount"
|
|
||||||
|
|
||||||
balanceassertionp :: JournalParser m BalanceAssertion
|
balanceassertionp :: JournalParser m BalanceAssertion
|
||||||
balanceassertionp = do
|
balanceassertionp = do
|
||||||
@ -1363,7 +1365,9 @@ tests_Common = tests "Common" [
|
|||||||
,astyle=amountstyle{asprecision=0, asdecimalpoint=Nothing}
|
,astyle=amountstyle{asprecision=0, asdecimalpoint=Nothing}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
,test "unit price, parenthesised" $ assertParse amountp "$10 (@) €0.5"
|
||||||
|
,test "total price, parenthesised" $ assertParse amountp "$10 (@@) €0.5"
|
||||||
|
]
|
||||||
|
|
||||||
,let p = lift (numberp Nothing) :: JournalParser IO (Quantity, Int, Maybe Char, Maybe DigitGroupStyle) in
|
,let p = lift (numberp Nothing) :: JournalParser IO (Quantity, Int, Maybe Char, Maybe DigitGroupStyle) in
|
||||||
test "numberp" $ do
|
test "numberp" $ do
|
||||||
|
|||||||
@ -549,6 +549,12 @@ There are several ways to record a transaction price:
|
|||||||
assets:dollars $-135 ; for $135
|
assets:dollars $-135 ; for $135
|
||||||
```
|
```
|
||||||
|
|
||||||
|
4.
|
||||||
|
5. Like 1 and 2, but the `@` or `@@` is parenthesised; this is for
|
||||||
|
compatibility with Ledger journals
|
||||||
|
([Virtual posting costs](https://www.ledger-cli.org/3.0/doc/ledger3.html#Virtual-posting-costs)),
|
||||||
|
and in hledger is equivalent to 1 and 2.
|
||||||
|
|
||||||
Use the [`-B/--cost`](hledger.html#reporting-options) flag to convert
|
Use the [`-B/--cost`](hledger.html#reporting-options) flag to convert
|
||||||
amounts to their transaction price's commodity, if any.
|
amounts to their transaction price's commodity, if any.
|
||||||
(mnemonic: "B" is from "cost Basis", as in Ledger).
|
(mnemonic: "B" is from "cost Basis", as in Ledger).
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user