diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c2b4e0..0e64a3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Field `crmToken` for `Owner` +- Field `externalInvoice` and `shortCode` for `Order` ## [1.0.0] - 2022-07-27 diff --git a/src/Order.hs b/src/Order.hs index a8d01ef..758c48b 100644 --- a/src/Order.hs +++ b/src/Order.hs @@ -27,11 +27,13 @@ data ZGoOrder = , qtotalZec :: Double , qlines :: [LineItem] , qpaid :: Bool + , qexternalInvoice :: T.Text + , qshortCode :: T.Text } deriving (Eq, Show, Generic) instance ToJSON ZGoOrder where - toJSON (ZGoOrder i a s ts c cur p t tZ l paid) = + toJSON (ZGoOrder i a s ts c cur p t tZ l paid eI sC) = case i of Just oid -> object @@ -46,6 +48,8 @@ instance ToJSON ZGoOrder where , "totalZec" .= tZ , "lines" .= l , "paid" .= paid + , "externalInvoice" .= eI + , "shortCode" .= sC ] Nothing -> object @@ -60,6 +64,8 @@ instance ToJSON ZGoOrder where , "totalZec" .= tZ , "lines" .= l , "paid" .= paid + , "externalInvoice" .= eI + , "shortCode" .= sC ] instance FromJSON ZGoOrder where @@ -76,6 +82,8 @@ instance FromJSON ZGoOrder where tZ <- obj .: "totalZec" l <- obj .: "lines" pd <- obj .: "paid" + eI <- obj .: "externalInvoice" + sC <- obj .: "shortCode" pure $ ZGoOrder (if not (null i) @@ -91,9 +99,11 @@ instance FromJSON ZGoOrder where tZ l pd + eI + sC instance Val ZGoOrder where - val (ZGoOrder i a s ts c cur p t tZ l pd) = + val (ZGoOrder i a s ts c cur p t tZ l pd eI sC) = if isJust i then Doc [ "_id" =: i @@ -107,6 +117,8 @@ instance Val ZGoOrder where , "totalZec" =: tZ , "lines" =: l , "paid" =: pd + , "externalInvoice" =: eI + , "shortCode" =: sC ] else Doc [ "address" =: a @@ -119,6 +131,8 @@ instance Val ZGoOrder where , "totalZec" =: tZ , "lines" =: l , "paid" =: pd + , "externalInvoice" =: eI + , "shortCode" =: sC ] cast' (Doc d) = do i <- B.lookup "_id" d @@ -132,7 +146,9 @@ instance Val ZGoOrder where tZ <- B.lookup "totalZec" d l <- B.lookup "lines" d pd <- B.lookup "paid" d - Just (ZGoOrder i a s ts c cur p t tZ l pd) + eI <- B.lookup "externalInvoice" d + sC <- B.lookup "shortCode" d + Just (ZGoOrder i a s ts c cur p t tZ l pd eI sC) cast' _ = Nothing -- Type to represent an order line item @@ -192,6 +208,8 @@ updateOrderTotals o = else 0) (qlines o) (qpaid o) + (qexternalInvoice o) + (qshortCode o) where newTotal :: ZGoOrder -> Double newTotal x = foldr tallyItems 0 (qlines x) diff --git a/test/Spec.hs b/test/Spec.hs index 83cd2b9..91751bf 100644 --- a/test/Spec.hs +++ b/test/Spec.hs @@ -249,6 +249,8 @@ main = do 0 [] False + "" + "" let ordTest = val myOrder case ordTest of Doc oT -> access p master "test" (insert_ "orders" oT) @@ -538,6 +540,8 @@ startAPI config = do 0 [] False + "" + "" let ordTest = val myOrder case ordTest of Doc oT -> access pipe master "test" (insert_ "orders" oT) @@ -567,7 +571,9 @@ instance Arbitrary ZGoOrder where t <- arbitrary tZ <- arbitrary l <- arbitrary - ZGoOrder i a s ts c cur p t tZ l <$> arbitrary + pd <- arbitrary + eI <- arbitrary + ZGoOrder i a s ts c cur p t tZ l pd eI <$> arbitrary instance Arbitrary LineItem where arbitrary = do