dev: postingAddInferredEquityPostings: cleanup

This commit is contained in:
Simon Michael 2024-01-25 14:52:24 -10:00
parent 4c7abc3d2f
commit 12e67e4859

View File

@ -545,16 +545,16 @@ postingToCost ToCost p
where where
nocosts = (not . any (isJust . acost) . amountsRaw) $ pamount p nocosts = (not . any (isJust . acost) . amountsRaw) $ pamount p
-- | Generate inferred equity postings from a 'Posting' using transaction prices. -- | Generate inferred equity postings from a 'Posting''s costs.
-- Make sure not to generate equity postings when there are already matched -- Make sure not to duplicate them when matching ones exist already.
-- conversion postings.
postingAddInferredEquityPostings :: Bool -> Text -> Posting -> [Posting] postingAddInferredEquityPostings :: Bool -> Text -> Posting -> [Posting]
postingAddInferredEquityPostings verbosetags equityAcct p postingAddInferredEquityPostings verbosetags equityAcct p
| "_price-matched" `elem` map fst (ptags p) = [p] | "_price-matched" `elem` map fst (ptags p) = [p]
| otherwise = taggedPosting : concatMap conversionPostings priceAmounts | otherwise = taggedPosting : concatMap conversionPostings costs
where where
costs = filter (isJust . acost) . amountsRaw $ pamount p
taggedPosting taggedPosting
| null priceAmounts = p | null costs = p
| otherwise = p{ ptags = ("_price-matched","") : ptags p } | otherwise = p{ ptags = ("_price-matched","") : ptags p }
conversionPostings amt = case acost amt of conversionPostings amt = case acost amt of
Nothing -> [] Nothing -> []
@ -581,8 +581,6 @@ postingAddInferredEquityPostings verbosetags equityAcct p
-- Take the commodity of an amount and collapse consecutive spaces to a single space -- Take the commodity of an amount and collapse consecutive spaces to a single space
commodity = T.unwords . filter (not . T.null) . T.words . acommodity commodity = T.unwords . filter (not . T.null) . T.words . acommodity
priceAmounts = filter (isJust . acost) . amountsRaw $ pamount p
-- | Make a market price equivalent to this posting's amount's unit -- | Make a market price equivalent to this posting's amount's unit
-- price, if any. -- price, if any.
postingPriceDirectivesFromCost :: Posting -> [PriceDirective] postingPriceDirectivesFromCost :: Posting -> [PriceDirective]