diff --git a/hledger-lib/Hledger/Read/Common.hs b/hledger-lib/Hledger/Read/Common.hs index 4fdad21b4..2bd3dcd4e 100644 --- a/hledger-lib/Hledger/Read/Common.hs +++ b/hledger-lib/Hledger/Read/Common.hs @@ -735,15 +735,17 @@ simplecommoditysymbolp :: TextParser m CommoditySymbol simplecommoditysymbolp = takeWhile1P Nothing (not . isNonsimpleCommodityChar) 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 '@' priceConstructor <- char '@' *> pure TotalPrice <|> pure UnitPrice + when parenthesised $ void $ char ')' lift (skipMany spacenonewline) priceAmount <- amountwithoutpricep -- "unpriced amount (specifying a price)" pure $ priceConstructor priceAmount - ) "price amount" balanceassertionp :: JournalParser m BalanceAssertion balanceassertionp = do @@ -1363,7 +1365,9 @@ tests_Common = tests "Common" [ ,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 test "numberp" $ do diff --git a/hledger-lib/hledger_journal.m4.md b/hledger-lib/hledger_journal.m4.md index 04039a731..719508230 100644 --- a/hledger-lib/hledger_journal.m4.md +++ b/hledger-lib/hledger_journal.m4.md @@ -549,6 +549,12 @@ There are several ways to record a transaction price: 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 amounts to their transaction price's commodity, if any. (mnemonic: "B" is from "cost Basis", as in Ledger).