@@ -1014,54 +1014,6 @@ journalInferCommodityStyles j =
1014
1014
Left e -> Left e
1015
1015
Right cs -> Right j{jinferredcommodities = dbg7 " journalInferCommodityStyles" cs}
1016
1016
1017
- -- | Given a list of amounts, in parse order (roughly speaking; see journalStyleInfluencingAmounts),
1018
- -- build a map from their commodity names to standard commodity
1019
- -- display formats. Can return an error message eg if inconsistent
1020
- -- number formats are found.
1021
- --
1022
- -- Though, these amounts may have come from multiple files, so we
1023
- -- shouldn't assume they use consistent number formats.
1024
- -- Currently we don't enforce that even within a single file,
1025
- -- and this function never reports an error.
1026
- --
1027
- commodityStylesFromAmounts :: [Amount ] -> Either String (M. Map CommoditySymbol AmountStyle )
1028
- commodityStylesFromAmounts amts =
1029
- Right $ M. fromList commstyles
1030
- where
1031
- commamts = groupSort [(acommodity as, as) | as <- amts]
1032
- commstyles = [(c, canonicalStyleFrom $ map astyle as) | (c,as) <- commamts]
1033
-
1034
- -- TODO: should probably detect and report inconsistencies here.
1035
- -- Though, we don't have the info for a good error message, so maybe elsewhere.
1036
- -- | Given a list of amount styles (assumed to be from parsed amounts
1037
- -- in a single commodity), in parse order, choose a canonical style.
1038
- -- This is:
1039
- -- the general style of the first amount,
1040
- -- with the first digit group style seen,
1041
- -- with the maximum precision of all.
1042
- --
1043
- canonicalStyleFrom :: [AmountStyle ] -> AmountStyle
1044
- canonicalStyleFrom [] = amountstyle
1045
- canonicalStyleFrom ss@ (s: _) =
1046
- s{asprecision= prec, asdecimalpoint= Just decmark, asdigitgroups= mgrps}
1047
- where
1048
- -- precision is maximum of all precisions
1049
- prec = maximumStrict $ map asprecision ss
1050
- -- identify the digit group mark (& group sizes)
1051
- mgrps = headMay $ mapMaybe asdigitgroups ss
1052
- -- if a digit group mark was identified above, we can rely on that;
1053
- -- make sure the decimal mark is different. If not, default to period.
1054
- defdecmark =
1055
- case mgrps of
1056
- Just (DigitGroups ' .' _) -> ' ,'
1057
- _ -> ' .'
1058
- -- identify the decimal mark: the first one used, or the above default,
1059
- -- but never the same character as the digit group mark.
1060
- -- urgh.. refactor..
1061
- decmark = case mgrps of
1062
- Just _ -> defdecmark
1063
- _ -> headDef defdecmark $ mapMaybe asdecimalpoint ss
1064
-
1065
1017
-- -- | Apply this journal's historical price records to unpriced amounts where possible.
1066
1018
-- journalApplyPriceDirectives :: Journal -> Journal
1067
1019
-- journalApplyPriceDirectives j@Journal{jtxns=ts} = j{jtxns=map fixtransaction ts}
@@ -1134,31 +1086,6 @@ journalToCost j@Journal{jtxns=ts} = j{jtxns=map (transactionToCost styles) ts}
1134
1086
-- Just (UnitPrice ma) -> c:(concatMap amountCommodities $ amounts ma)
1135
1087
-- Just (TotalPrice ma) -> c:(concatMap amountCommodities $ amounts ma)
1136
1088
1137
- -- | Get an ordered list of amounts in this journal which can
1138
- -- influence canonical amount display styles. Those amounts are, in
1139
- -- the following order:
1140
- --
1141
- -- * amounts in market price (P) directives (in parse order)
1142
- -- * posting amounts in transactions (in parse order)
1143
- -- * the amount in the final default commodity (D) directive
1144
- --
1145
- -- Transaction price amounts (posting amounts' aprice field) are not included.
1146
- --
1147
- journalStyleInfluencingAmounts :: Journal -> [Amount ]
1148
- journalStyleInfluencingAmounts j =
1149
- dbg7 " journalStyleInfluencingAmounts" $
1150
- catMaybes $ concat [
1151
- [mdefaultcommodityamt]
1152
- ,map (Just . pdamount) $ jpricedirectives j
1153
- ,map Just $ concatMap amounts $ map pamount $ journalPostings j
1154
- ]
1155
- where
1156
- -- D's amount style isn't actually stored as an amount, make it into one
1157
- mdefaultcommodityamt =
1158
- case jparsedefaultcommodity j of
1159
- Just (symbol,style) -> Just nullamt{acommodity= symbol,astyle= style}
1160
- Nothing -> Nothing
1161
-
1162
1089
-- overcomplicated/unused amount traversal stuff
1163
1090
--
1164
1091
-- | Get an ordered list of 'AmountStyle's from the amounts in this
@@ -1510,39 +1437,4 @@ tests_Journal = tests "Journal" [
1510
1437
1511
1438
]
1512
1439
1513
- ,tests " commodityStylesFromAmounts" $ [
1514
-
1515
- -- Journal similar to the one on #1091:
1516
- -- 2019/09/24
1517
- -- (a) 1,000.00
1518
- --
1519
- -- 2019/09/26
1520
- -- (a) 1000,000
1521
- --
1522
- test " 1091a" $ do
1523
- commodityStylesFromAmounts [
1524
- nullamt{aquantity= 1000 , astyle= AmountStyle L False (Precision 3 ) (Just ' ,' ) Nothing }
1525
- ,nullamt{aquantity= 1000 , astyle= AmountStyle L False (Precision 2 ) (Just ' .' ) (Just (DigitGroups ' ,' [3 ]))}
1526
- ]
1527
- @?=
1528
- -- The commodity style should have period as decimal mark
1529
- -- and comma as digit group mark.
1530
- Right (M. fromList [
1531
- (" " , AmountStyle L False (Precision 3 ) (Just ' .' ) (Just (DigitGroups ' ,' [3 ])))
1532
- ])
1533
- -- same journal, entries in reverse order
1534
- ,test " 1091b" $ do
1535
- commodityStylesFromAmounts [
1536
- nullamt{aquantity= 1000 , astyle= AmountStyle L False (Precision 2 ) (Just ' .' ) (Just (DigitGroups ' ,' [3 ]))}
1537
- ,nullamt{aquantity= 1000 , astyle= AmountStyle L False (Precision 3 ) (Just ' ,' ) Nothing }
1538
- ]
1539
- @?=
1540
- -- The commodity style should have period as decimal mark
1541
- -- and comma as digit group mark.
1542
- Right (M. fromList [
1543
- (" " , AmountStyle L False (Precision 3 ) (Just ' .' ) (Just (DigitGroups ' ,' [3 ])))
1544
- ])
1545
-
1546
- ]
1547
-
1548
1440
]
0 commit comments