Commit Graph

172 Commits

Author SHA1 Message Date
Simon Michael
d6e075dacd refactor journalModifyTransactions, modifyTransactions
API changes:

Hledger.Data.TransactionModifier
-transactionModifierToFunction
+modifyTransactions

Hledger.Read.Common.applyTransactionModifiers -> Hledger.Data.Journal.journalModifyTransactions
2019-02-01 11:31:04 -08:00
Simon Michael
763903ebda journal: save account directives' comments, tags, declaration order 2019-01-18 16:40:35 -08:00
Simon Michael
70b11ed0a4 journal: make balance assertions exact again (#941)
Going with option 1b from the issue: calculated and asserted amounts
are compared exactly, disregarding display precision.
But now balance assertion failure messages show those exact amounts at
full precision, avoiding confusion.
2019-01-08 16:51:11 +00:00
Simon Michael
c331be7f23 journal: clarify balance assertion/display precision more (#941) 2019-01-06 22:17:20 +00:00
Simon Michael
187fcf75ed journal: clarify balance assertion/display precision interaction
Surprisingly, balance assertions were checking to maximum precision,
which meant it was possible, with a display-precision-limiting
commodity directive, to have a failing assertion with the error
message showing asserted and actual amounts that looked the same.

Now we round the calculated account balance (but not the asserted
balance) to display precision before comparing. This should ensure
assertions always behave as you would expect from visual inspection.
2019-01-06 08:30:54 +00:00
Simon Michael
72eb48bb29 lib: clarify checkBalanceAssertion etc. 2019-01-06 08:24:07 +00:00
Simon Michael
6f36702141 lib: rename, reposition tprecedingcomment field 2019-01-05 07:35:54 +00:00
Jesse Rosenthal
11a5809c5c journal: improve unassignable error. 2018-12-02 13:29:00 -08:00
Jesse Rosenthal
07d0a003a3 journal: fill unassignable list from account names. 2018-12-02 13:29:00 -08:00
Jesse Rosenthal
597b1b8ccd journal: check assignments against unassignable list 2018-12-02 13:29:00 -08:00
Jesse Rosenthal
ff455689a3 journal: add new state field for unassignable accounts
This should eventually include accountnames from transaction
modifiers (if `--auto` is enabled), or periodic transactions (if
`--forecast` is enabled).
2018-12-02 13:29:00 -08:00
Samuel May
e57ef9e9a9 lib: journal: Add support for exact assertions 2018-10-22 09:55:14 -07:00
Samuel May
6c31393dd3 lib: Groundwork allowing multi-commodity assertions 2018-10-22 09:55:14 -07:00
Samuel May
cde91fc5f4 lib: Make BalanceAssertion a full datatype
Note: simplifies/moves whitespace parsing out of the balance assertion
parser.
2018-10-22 09:55:14 -07:00
Jesse Rosenthal
a6a73e36e3 Finish removing journalFinalise (#903)
* journal: Get rid of `journalFinalise` and use granular functions

Complete the process started in 53b3e2bd. This gets rid of the
`journalFinalise` function and uses the smaller steps, in order to
have more granular control.

* journal: Change order of operations in finalization

We want to make sure that we add the filepath after the order is
reversed, so the added filepath is on the head and not the tail (as it
would be if it were reversed after it was added).

* journal: Refine granular finalization functions

This commit fixes two of the granular finalization functions:

1. Rename `journalSetTime` to `journalSetLastReadTime` and improve
   documentation.

2. Remove `journalSetFilePath`. It's redundant with `journalAddFile`
   currently in `Hledger.Read.Common`. The only difference between the
   functions is where the file is added (we keep the one in which it
   is added to the tail), so we change the position vis-a-vis
   reversal.
2018-10-16 08:51:51 -07:00
Jesse Rosenthal
53b3e2bd94 journal: split up the parts of journalFinalise, and use them as needed.
`journalFinalise` is only used in the `parseAndFinaliseJournal`
functions, but it needs to be run differently at different stages when
transaction modifiers are applied. This change breaks it into smaller
functions, and uses those smaller parts in `parseAndFinaliseJournal`
as needed.
2018-10-12 07:39:53 -07:00
Jesse Rosenthal
b346d7f701 Journal: make reordering optional in journalFinalise
Currently `journalFinalise` always reverses the order of
entries. However, if there are automated transactions, we might need
to run it twice. This adds a boolean flag to make reordering
optional. This will be used in the `parseAndFinaliseJournal`
functions.
2018-10-12 07:39:53 -07:00
Simon Michael
605a082d77 bs/bse/cf/is: use account type declarations if any
These commands now detect the account types declared by account directives.
Whenever such declarations are not present, built-in regular expressions
are used, as before.
2018-10-09 14:24:59 -10:00
Simon Michael
c1236fa6e9 journal: account directives can declare account types
Previously you had to use one of the standard english account names
(assets, liabilities..) for top-level accounts, if you wanted to use
the bs/bse/cf/is commands.
Now, account directives can specify which of the big five categories
an account belongs to - asset, liability, equity, revenue or expense -
by writing one of the letters A, L, E, R or X two or more spaces after
the account name (where the numeric account code used to be).

This might change. Some thoughts influencing the current syntax:
- easy to type and read
- does not require multiple lines
- does not depend on any particular account numbering scheme
- allows more types later if needed
- still anglocentric, but only a little
- could be treated as syntactic sugar for account tags later
- seems to be compatible with (ignored by) current Ledger

The current design permits unlimited account type declarations anywhere
in the account tree. So you could declare a liability account somewhere
under assets, and maybe a revenue account under that, and another asset
account even further down. In such cases you start to see oddities like
accounts appearing in multiple places in a tree-mode report. In theory
the reports will still behave reasonably, but this has not been tested
too hard. In any case this is clearly too much freedom. I have left it
this way, for now, in case it helps with:

- modelling contra accounts ?
- multiple files. I suspect the extra expressiveness may come in handy
  when combining multiple files with account type declarations,
  rewriting account names, apply parent accounts etc.
  If we only allowed type declarations on top-level accounts, or
  only allowed a single account of each type, complications seem likely.
2018-10-09 14:24:59 -10:00
Simon Michael
6c57629b8c lib: fix posting-date-and-balance-assignment error properly (#894) 2018-10-09 16:08:47 -07:00
Simon Michael
36fdeceb6c lib: tweak posting-date-no-amount-balance-assertion error (#894) 2018-10-09 14:15:52 -07:00
Alex Chen
2cbc41e088 Merge branch 'master' into ExceptTLayer 2018-10-09 11:19:45 -06:00
Simon Michael
2ba135e402 lib: journal: fix wrong txn rendering in balance assertion errors 2018-10-06 09:31:22 -10:00
Alex Chen
5e1f0ba6f7 lib: add a field to 'Journal' for a stack of include files
- In anticipation of megaparsec 7, which removes support for stacks of
  include files (as far as I can tell)
- Intended for the 'StateT Journal' layer of the parser
  - A stack of include files would be better in a 'ReaderT' layer, but I
    don't want to add another layer to the parser
- Intended for detecting cycles of include files
  - Potential issue: for proper error messages for include file cycles,
    we must remember to provide the filepath of the root journal file via
    the initial journal state passed to a 'JournalParser'; I imagine
    that we may forget to do so because in all other cases it is okay
    not to do so.
2018-09-29 22:32:27 -06:00
Simon Michael
2960c9209f lib: whitespace 2018-09-27 10:51:36 -10:00
Simon Michael
3de8c11de1 journal: a new account sorting mechanism, and a bunch of sorting fixes
A bunch of account sorting changes that got intermingled.

First, account codes have been dropped. They can still be parsed and
will be ignored, for now. I don't know if anyone used them.
Instead, account display order is now controlled by the order of account
directives, if any. From the mail list:

  I'd like to drop account codes, introduced in hledger 1.9 to control
  the display order of accounts. In my experience,

  - they are tedious to maintain
  - they duplicate/compete with the natural tendency to arrange account
    directives to match your mental chart of accounts
  - they duplicate/compete with the tree structure created by account
    names

  and it gets worse if you think about using them more extensively,
  eg to classify accounts by type.

  Instead, I plan to just let the position (parse order) of account
  directives determine the display order of those declared accounts.
  Undeclared accounts will be displayed after declared accounts,
  sorted alphabetically as usual.

Second, the various account sorting modes have been implemented more
widely and more correctly. All sorting modes (alphabetically, by account
declaration, by amount) should now work correctly in almost all commands
and modes (non-tabular and tabular balance reports, tree and flat modes,
the accounts command). Sorting bugs have been fixed, eg #875.
Only the budget report (balance --budget) does not yet support sorting.

Comprehensive functional tests for sorting in the accounts and balance
commands have been added. If you are confused by some sorting behaviour,
studying these tests is recommended, as sorting gets tricky.
2018-09-22 21:45:07 -10:00
Simon Michael
059ad9eb76 refactor: jaccounts -> jdeclaredaccounts 2018-09-17 05:52:13 -07:00
Simon Michael
91b111b60d rename easytests_* to tests_* 2018-09-06 13:13:26 -07:00
Simon Michael
4003264129 lib: drop HUnit helpers, rename expectEqPP 2018-09-04 13:52:36 -07:00
Simon Michael
d5c756e6c8 tests: Journal -> easytest 2018-09-04 10:10:10 -07:00
Simon Michael
f108b56e61 uniquify modules' easytests, simplify imports 2018-08-20 14:31:31 +01:00
Simon Michael
150b40e465 tests: remove empty scope 2018-08-19 18:07:33 +01:00
Simon Michael
d778a92561 tests: export HUnit/EasyTest from Hledger.Utils.Test; more helpers 2018-08-18 15:19:59 +01:00
Simon Michael
b4c336c874 test/_test/it/_it helpers; refactor easytests
This makes skipping/unskipping tests easier, and improves readability
a bit.

Note it's also possible to just write the test name with no preceding
function, when the type is constrained (see Journal.hs).
2018-08-17 13:40:37 +01:00
Simon Michael
50d666d5a0 test: refactor, document, organise easytests, port amountp tests (#812) 2018-08-15 19:58:07 +01:00
Simon Michael
efae8f8f2a lib: comment 2018-08-14 16:05:06 +01:00
Jakub Zárybnický
c67404c73d lib: Fix compile errors in tests 2018-08-14 16:05:06 +01:00
Simon Michael
efc54c4c25 lib: ModifierTransaction -> TransactionModifier; try to clarify a bit 2018-07-30 19:38:21 +01:00
Simon Michael
0b380971f7 journal: require a decimal point in commodity/format/D directives
A commodity directive that doesn't specify the decimal point character
increases ambiguity and the chance of misparsing numbers, especially
as it overrides all style information inferred from the journal amounts.
In some cases it caused amounts with a decimal point to be parsed as if
with a digit group separator so 1.234 became 1234.

We could augment it with extra info from the journal amounts, when available,
but it would still be possible to be ambiguous, and that won't be obvious.

A commodity directive is what we recommend to nail down the style.
It seems the simple and really only way to do this reliably is to require
an explicit decimal point character. Most folks probably do this already.

Unfortunately, it makes another potential incompatiblity with ledger and
beancount journals. But the error message will be clear and easy to
work around.
2018-04-20 21:56:06 -07:00
Simon Michael
3d4f5600ae journal: infer and balance amounts with standard amount styles (fix #737)
Inferred amounts now have the appropriate standard amount style applied.
And when checking for balanced transactions, amount styles declared with
commodity directives are also used (previously only inferred amount styles were).
2018-04-20 13:40:05 -07:00
Simon Michael
91e3ddd4fb lib: refactor 2018-04-20 05:24:09 -07:00
Dmitry Astapov
d82370d10b lib, app, web: remove differences between command line and journal file aliases 2018-04-17 16:09:11 -07:00
Simon Michael
4d562ef068 lib: don't count periodic/modifier txns in Journal debug output 2018-03-29 16:45:34 +01:00
Simon Michael
84579bb1b4 silence redundant import warnings with ghc 8.4 2018-03-24 22:51:56 +00:00
Peter Simons
4c5a58ec1e hledger-lib: add missing Semigroup instance for Journal
GHC 8.4.1 makes Semigroup a superclass of Monoid. See
https://prime.haskell.org/wiki/Libraries/Proposals/SemigroupMonoid
for details.
2018-03-12 23:17:14 +00:00
Simon Michael
d420a8b534 journal: account directive: parse and store a numeric account code also 2018-01-23 11:33:23 -08:00
Simon Michael
d15a2dc4c0 lib: fix journalAccountNames doc
[ci skip]
2017-12-29 12:34:51 -08:00
Simon Michael
ddef7d722d lib: update journal account names api
Now we have:

-- | Sorted unique account names posted to by this journal's transactions.
journalAccountNamesUsed :: Journal -> [AccountName]

-- | Sorted unique account names implied by this journal's transactions -
-- accounts posted to and all their implied parent accounts.
journalAccountNamesImplied :: Journal -> [AccountName]

-- | Sorted unique account names declared by account directives in this journal.
journalAccountNamesDeclared :: Journal -> [AccountName]

-- | Sorted unique account names declared by account directives or posted to
-- by transactions in this journal.
journalAccountNamesDeclaredOrUsed :: Journal -> [AccountName]

-- | Sorted unique account names declared by account directives, or posted to
-- or implied as parents by transactions in this journal.
journalAccountNamesDeclaredOrImplied :: Journal -> [AccountName]

-- | Convenience/compatibility alias for journalAccountNamesImpliedOrUsed.
journalAccountNames :: Journal -> [AccountName]
2017-12-29 12:18:04 -08:00
Mykola Orliuk
fa2e680b2e lib: fix styles after cost application
Fixes simonmichael/hledger#509
2017-12-04 12:26:26 -08:00
Dmitry Astapov
6f92e70575 lib: remove needless numeric comparisons in bal/bs
accountsFromPostings is currently doing excessive work when adding up
postings in each account. It sorts (accountName, amount) tuples which
cause amounts in them to be compared. There is no need to look at amount
here at all since subsequent summing up and counting does not depend on
order. It is enough to sort by accountname only.

Went through similar pieces of code, made them all look uniform.
2017-11-29 07:08:18 -08:00