Add fields to Order

This commit is contained in:
Rene Vergara 2022-08-03 14:13:33 -05:00
parent 0f333fd92c
commit 18533b0487
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
3 changed files with 29 additions and 4 deletions

View file

@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added ### Added
- Field `crmToken` for `Owner` - Field `crmToken` for `Owner`
- Field `externalInvoice` and `shortCode` for `Order`
## [1.0.0] - 2022-07-27 ## [1.0.0] - 2022-07-27

View file

@ -27,11 +27,13 @@ data ZGoOrder =
, qtotalZec :: Double , qtotalZec :: Double
, qlines :: [LineItem] , qlines :: [LineItem]
, qpaid :: Bool , qpaid :: Bool
, qexternalInvoice :: T.Text
, qshortCode :: T.Text
} }
deriving (Eq, Show, Generic) deriving (Eq, Show, Generic)
instance ToJSON ZGoOrder where 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 case i of
Just oid -> Just oid ->
object object
@ -46,6 +48,8 @@ instance ToJSON ZGoOrder where
, "totalZec" .= tZ , "totalZec" .= tZ
, "lines" .= l , "lines" .= l
, "paid" .= paid , "paid" .= paid
, "externalInvoice" .= eI
, "shortCode" .= sC
] ]
Nothing -> Nothing ->
object object
@ -60,6 +64,8 @@ instance ToJSON ZGoOrder where
, "totalZec" .= tZ , "totalZec" .= tZ
, "lines" .= l , "lines" .= l
, "paid" .= paid , "paid" .= paid
, "externalInvoice" .= eI
, "shortCode" .= sC
] ]
instance FromJSON ZGoOrder where instance FromJSON ZGoOrder where
@ -76,6 +82,8 @@ instance FromJSON ZGoOrder where
tZ <- obj .: "totalZec" tZ <- obj .: "totalZec"
l <- obj .: "lines" l <- obj .: "lines"
pd <- obj .: "paid" pd <- obj .: "paid"
eI <- obj .: "externalInvoice"
sC <- obj .: "shortCode"
pure $ pure $
ZGoOrder ZGoOrder
(if not (null i) (if not (null i)
@ -91,9 +99,11 @@ instance FromJSON ZGoOrder where
tZ tZ
l l
pd pd
eI
sC
instance Val ZGoOrder where 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 if isJust i
then Doc then Doc
[ "_id" =: i [ "_id" =: i
@ -107,6 +117,8 @@ instance Val ZGoOrder where
, "totalZec" =: tZ , "totalZec" =: tZ
, "lines" =: l , "lines" =: l
, "paid" =: pd , "paid" =: pd
, "externalInvoice" =: eI
, "shortCode" =: sC
] ]
else Doc else Doc
[ "address" =: a [ "address" =: a
@ -119,6 +131,8 @@ instance Val ZGoOrder where
, "totalZec" =: tZ , "totalZec" =: tZ
, "lines" =: l , "lines" =: l
, "paid" =: pd , "paid" =: pd
, "externalInvoice" =: eI
, "shortCode" =: sC
] ]
cast' (Doc d) = do cast' (Doc d) = do
i <- B.lookup "_id" d i <- B.lookup "_id" d
@ -132,7 +146,9 @@ instance Val ZGoOrder where
tZ <- B.lookup "totalZec" d tZ <- B.lookup "totalZec" d
l <- B.lookup "lines" d l <- B.lookup "lines" d
pd <- B.lookup "paid" 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 cast' _ = Nothing
-- Type to represent an order line item -- Type to represent an order line item
@ -192,6 +208,8 @@ updateOrderTotals o =
else 0) else 0)
(qlines o) (qlines o)
(qpaid o) (qpaid o)
(qexternalInvoice o)
(qshortCode o)
where where
newTotal :: ZGoOrder -> Double newTotal :: ZGoOrder -> Double
newTotal x = foldr tallyItems 0 (qlines x) newTotal x = foldr tallyItems 0 (qlines x)

View file

@ -249,6 +249,8 @@ main = do
0 0
[] []
False False
""
""
let ordTest = val myOrder let ordTest = val myOrder
case ordTest of case ordTest of
Doc oT -> access p master "test" (insert_ "orders" oT) Doc oT -> access p master "test" (insert_ "orders" oT)
@ -538,6 +540,8 @@ startAPI config = do
0 0
[] []
False False
""
""
let ordTest = val myOrder let ordTest = val myOrder
case ordTest of case ordTest of
Doc oT -> access pipe master "test" (insert_ "orders" oT) Doc oT -> access pipe master "test" (insert_ "orders" oT)
@ -567,7 +571,9 @@ instance Arbitrary ZGoOrder where
t <- arbitrary t <- arbitrary
tZ <- arbitrary tZ <- arbitrary
l <- 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 instance Arbitrary LineItem where
arbitrary = do arbitrary = do