ref: journalFinalise: clarify sequence, top to bottom
This commit is contained in:
		
							parent
							
								
									91441bad8f
								
							
						
					
					
						commit
						885a4fcfec
					
				| @ -317,42 +317,28 @@ parseAndFinaliseJournal' parser iopts f txt = do | |||||||
| -- - check all commodities have been declared if in strict mode | -- - check all commodities have been declared if in strict mode | ||||||
| -- | -- | ||||||
| journalFinalise :: InputOpts -> FilePath -> Text -> ParsedJournal -> ExceptT String IO Journal | journalFinalise :: InputOpts -> FilePath -> Text -> ParsedJournal -> ExceptT String IO Journal | ||||||
| journalFinalise iopts@InputOpts{auto_,infer_equity_,balancingopts_,strict_} f txt pj = do | journalFinalise iopts@InputOpts{auto_,infer_equity_,balancingopts_,strict_,_ioDay} f txt pj = do | ||||||
|   t <- liftIO getPOSIXTime |   t <- liftIO getPOSIXTime | ||||||
|     -- Infer and apply canonical styles for each commodity (or throw an error). |   liftEither $ do | ||||||
|     -- This affects transaction balancing/assertions/assignments, so needs to be done early. |     let pj2 = pj | ||||||
|     liftEither $ checkAddAndBalance (_ioDay iopts) <=< journalApplyCommodityStyles $ |  | ||||||
|         pj{jglobalcommoditystyles=fromMaybe mempty $ commodity_styles_ balancingopts_}  -- save any global commodity styles |  | ||||||
|         & journalAddFile (f, txt)           -- save the main file's info |  | ||||||
|           & journalSetLastReadTime t   -- save the last read time |           & journalSetLastReadTime t   -- save the last read time | ||||||
|  |           & journalAddFile (f, txt)    -- save the main file's info | ||||||
|           & journalReverse             -- convert all lists to the order they were parsed           |           & journalReverse             -- convert all lists to the order they were parsed           | ||||||
|   where |     pj3 <- pj2{jglobalcommoditystyles=fromMaybe mempty $ commodity_styles_ balancingopts_} | ||||||
|     checkAddAndBalance d j = do |           & journalApplyCommodityStyles                   -- Infer and apply commodity styles - should be done early | ||||||
|         newj <- j |     j <- pj3 | ||||||
|           -- Add account tags to postings' tags |       &   journalPostingsAddAccountTags                  -- Add account tags to postings' tags | ||||||
|           & journalPostingsAddAccountTags |       &   journalAddForecast (forecastPeriod iopts pj3)  -- Add forecast transactions if enabled | ||||||
|           -- Add forecast transactions if enabled |       &   journalPostingsAddAccountTags                  -- Add account tags again to affect forecast transactions  -- PERF: just to the new transactions ? | ||||||
|           & journalAddForecast (forecastPeriod iopts j) |       &   (if auto_ && not (null $ jtxnmodifiers pj3) then journalAddAutoPostings _ioDay balancingopts_ else pure)  -- Add auto postings if enabled | ||||||
|           -- Add account tags again to affect forecast transactions  -- PERF: just to the new transactions ? |       >>= Right . journalPostingsAddAccountTags          -- Add account tags again to affect auto postings  -- PERF: just to the new postings ? | ||||||
|           & journalPostingsAddAccountTags |       >>= journalBalanceTransactions balancingopts_      -- Balance all transactions and maybe check balance assertions. | ||||||
|           -- Add auto postings if enabled |       <&> (if infer_equity_ then journalAddInferredEquityPostings else id)  -- Add inferred equity postings, after balancing transactions and generating auto postings | ||||||
|           & (if auto_ && not (null $ jtxnmodifiers j) then journalAddAutoPostings d balancingopts_ else pure) |       <&> journalInferMarketPricesFromTransactions       -- infer market prices from commodity-exchanging transactions | ||||||
|           -- Add account tags again to affect auto postings  -- PERF: just to the new postings ? |  | ||||||
|           >>= Right . journalPostingsAddAccountTags |  | ||||||
|           -- Balance all transactions and maybe check balance assertions. |  | ||||||
|           >>= journalBalanceTransactions balancingopts_ |  | ||||||
|           -- Add inferred equity postings, after balancing transactions and generating auto postings |  | ||||||
|           <&> (if infer_equity_ then journalAddInferredEquityPostings else id) |  | ||||||
|           -- infer market prices from commodity-exchanging transactions |  | ||||||
|           <&> journalInferMarketPricesFromTransactions |  | ||||||
| 
 |  | ||||||
|     when strict_ $ do |     when strict_ $ do | ||||||
|           -- If in strict mode, check all postings are to declared accounts |       journalCheckAccountsDeclared j                     -- If in strict mode, check all postings are to declared accounts | ||||||
|           journalCheckAccountsDeclared newj |       journalCheckCommoditiesDeclared j                  -- and using declared commodities | ||||||
|           -- and using declared commodities |     return j | ||||||
|           journalCheckCommoditiesDeclared newj |  | ||||||
| 
 |  | ||||||
|         return newj |  | ||||||
| 
 | 
 | ||||||
| -- | To all postings in the journal, add any tags from their account  | -- | To all postings in the journal, add any tags from their account  | ||||||
| -- (including those inherited from parent accounts). | -- (including those inherited from parent accounts). | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user