;lib: refactor, clarify finaliseJournal a bit
This commit is contained in:
		
							parent
							
								
									c67ffedea5
								
							
						
					
					
						commit
						fccd88149d
					
				| @ -110,6 +110,7 @@ import Data.Char | |||||||
| import Data.Data | import Data.Data | ||||||
| import Data.Decimal (DecimalRaw (Decimal), Decimal) | import Data.Decimal (DecimalRaw (Decimal), Decimal) | ||||||
| import Data.Default | import Data.Default | ||||||
|  | import Data.Function ((&)) | ||||||
| import Data.Functor.Identity | import Data.Functor.Identity | ||||||
| import "base-compat-batteries" Data.List.Compat | import "base-compat-batteries" Data.List.Compat | ||||||
| import Data.List.NonEmpty (NonEmpty(..)) | import Data.List.NonEmpty (NonEmpty(..)) | ||||||
| @ -278,43 +279,25 @@ finaliseJournal iopts f txt pj = do | |||||||
|   -- transactions before they get reversesd to normal order. |   -- transactions before they get reversesd to normal order. | ||||||
|   case journalApplyCommodityStyles pj of |   case journalApplyCommodityStyles pj of | ||||||
|     Left e    -> throwError e |     Left e    -> throwError e | ||||||
|     Right pj' ->  |     Right pj' -> either throwError return $ | ||||||
|       -- Finalise the parsed journal. |       pj' | ||||||
|       let fj = |       & journalAddFile (f, txt)  -- save the file path and content | ||||||
|             if auto_ iopts && (not . null . jtxnmodifiers) pj |       & journalSetLastReadTime t -- save the last read time | ||||||
|             then |       & journalReverse           -- convert all lists to parse order | ||||||
|               -- When automatic postings are active, we finalise twice: |       & if not (auto_ iopts) || null (jtxnmodifiers pj) | ||||||
|               -- once before and once after. However, if we are running it |         then | ||||||
|               -- twice, we don't check assertions the first time (they might |           -- Auto postings are not active. | ||||||
|               -- be false pending modifiers) and we don't reorder the second |           -- Balance all transactions and maybe check balance assertions. | ||||||
|               -- time. If we are only running once, we reorder and follow |           journalBalanceTransactions (not $ ignore_assertions_ iopts) | ||||||
|               -- the options for checking assertions. |         else \j -> do  -- Either monad | ||||||
|               -- |           -- Auto postings are active. | ||||||
|               -- first pass, doing most of the work |           -- Balance all transactions without checking balance assertions, | ||||||
|               ( |           -- then add the auto postings, then check balance assertions. | ||||||
|                (journalModifyTransactions <$>) $  -- add auto postings after balancing ? #893b fails |           -- (Note adding auto postings after balancing means #893b fails; | ||||||
|                journalBalanceTransactions False $ -- balance transactions without checking assertions |           -- adding them before balancing probably means #893a, #928, #938 fail.) | ||||||
|                -- journalModifyTransactions <$>   -- add auto postings before balancing ? probably #893a, #928, #938 fail |           j' <- journalBalanceTransactions False j | ||||||
|                journalReverse $ |           let j'' = journalModifyTransactions j' | ||||||
|                journalSetLastReadTime t $ |           journalBalanceTransactions (not $ ignore_assertions_ iopts) j'' | ||||||
|                journalAddFile (f, txt) $ |  | ||||||
|                pj') |  | ||||||
|               -- balance transactions a second time, now just checking balance assertions |  | ||||||
|               >>= (\j -> |  | ||||||
|                  journalBalanceTransactions (not $ ignore_assertions_ iopts) $ |  | ||||||
|                  j) |  | ||||||
| 
 |  | ||||||
|             else |  | ||||||
|               -- automatic postings are not active |  | ||||||
|               journalBalanceTransactions (not $ ignore_assertions_ iopts) $ |  | ||||||
|               journalReverse $ |  | ||||||
|               journalSetLastReadTime t $ |  | ||||||
|               journalAddFile (f, txt) $ |  | ||||||
|               pj' |  | ||||||
|       in |  | ||||||
|         case fj of |  | ||||||
|           Left e  -> throwError e |  | ||||||
|           Right j -> return j |  | ||||||
| 
 | 
 | ||||||
| setYear :: Year -> JournalParser m () | setYear :: Year -> JournalParser m () | ||||||
| setYear y = modify' (\j -> j{jparsedefaultyear=Just y}) | setYear y = modify' (\j -> j{jparsedefaultyear=Just y}) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user