Skip to content

Commit 9e3cdef

Browse files
committed
lib: balance assertion docs (#290)
[ci skip]
1 parent 173529e commit 9e3cdef

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

hledger-lib/Hledger/Data/Types.hs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,29 @@ instance Show Status where -- custom show.. bad idea.. don't do it..
239239

240240
-- | The amount to compare an account's balance to, to verify that the history
241241
-- leading to a given point is correct or to set the account to a known value.
242+
--
243+
-- Different kinds of balance assertion (from #290):
244+
--
245+
-- * simple assertions: single-commodity, non-total, subaccount-exclusive
246+
-- assertions, as in Ledger (syntax: `=`). See definitions below.
247+
--
248+
-- * subaccount-inclusive assertions: asserting the balance of an account
249+
-- including all its subaccounts' balances. Not implemented, proposed by #290.
250+
--
251+
-- * multicommodity assertions: writing multiple amounts separated by + to
252+
-- assert a multicommodity balance, in a single assertion. Not implemented,
253+
-- proposed by #934. In current hledger you can assert a multicommodity
254+
-- balance by using multiple postings/assertions. But in either case, the
255+
-- balance might contain additional unasserted commodities. To disallow that
256+
-- you need...
257+
--
258+
-- * total assertions: asserting that the balance is as written, with no extra
259+
-- commodities in the account. Added by #902, with syntax `==`. I sometimes
260+
-- wish this was the default behaviour, of `=`.
261+
--
242262
data BalanceAssertion = BalanceAssertion {
243-
baamount :: Amount, -- ^ the expected value of a particular commodity
244-
baexact :: Bool, -- ^ whether the assertion is exclusive, and doesn't allow other commodities alongside 'baamount'
263+
baamount :: Amount, -- ^ the expected balance of a single commodity
264+
baexact :: Bool, -- ^ whether the assertion is total, ie disallowing amounts in other commodities
245265
baposition :: GenericSourcePos
246266
} deriving (Eq,Typeable,Data,Generic,Show)
247267

@@ -256,7 +276,8 @@ data Posting = Posting {
256276
pcomment :: Text, -- ^ this posting's comment lines, as a single non-indented multi-line string
257277
ptype :: PostingType,
258278
ptags :: [Tag], -- ^ tag names and values, extracted from the comment
259-
pbalanceassertion :: Maybe BalanceAssertion, -- ^ optional: the expected balance in this commodity in the account after this posting
279+
pbalanceassertion :: Maybe BalanceAssertion, -- ^ an expected balance in the account after this posting,
280+
-- in a single commodity, excluding subaccounts.
260281
ptransaction :: Maybe Transaction, -- ^ this posting's parent transaction (co-recursive types).
261282
-- Tying this knot gets tedious, Maybe makes it easier/optional.
262283
porigin :: Maybe Posting -- ^ When this posting has been transformed in some way

0 commit comments

Comments
 (0)