diff --git a/CHANGELOG.md b/CHANGELOG.md index 47819a3..b4d4e29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed +- Fixed calculation of order total to ensure 8 decimal places - Fixed test for looking for an order with incorrect ID - Fixed payment scan to focus only on new transactions diff --git a/src/Order.hs b/src/Order.hs index 94713cf..dae4542 100644 --- a/src/Order.hs +++ b/src/Order.hs @@ -188,7 +188,7 @@ updateOrderTotals o = (qprice o) (newTotal o) (if qprice o /= 0 - then newTotal o / qprice o + then roundZec (newTotal o / qprice o) else 0) (qlines o) (qpaid o) @@ -215,3 +215,7 @@ markOrderPaid i = modify (select ["_id" =: (read i :: B.ObjectId)] "orders") ["$set" =: ["paid" =: True]] + +-- | Helper function to round to 8 decimal places +roundZec :: Double -> Double +roundZec n = fromInteger (round $ n * (10 ^ 8)) / (10.0 ^^ 8) diff --git a/src/ZGoBackend.hs b/src/ZGoBackend.hs index 63a9386..568b8d3 100644 --- a/src/ZGoBackend.hs +++ b/src/ZGoBackend.hs @@ -294,6 +294,10 @@ decodeHexText h = E.decodeUtf8With lenientDecode $ BS.pack $ hexRead h encodeHexText :: T.Text -> String encodeHexText t = T.unpack . toText . fromBytes $ E.encodeUtf8 t +-- | Helper function to round to 8 decimal places +roundZec :: Double -> Double +roundZec n = fromInteger (round $ n * (10 ^ 8)) / (10.0 ^^ 8) + -- Types for the ZGo database documents -- | Type to model a country for the database's country list data Country = @@ -788,8 +792,7 @@ scanPayments config pipe = do getOrderId re t = do let reg = matchAllText re (T.unpack $ zmemo t) if not (null reg) - then do - fst $ head reg ! 1 + then fst $ head reg ! 1 else "" -- | RPC methods