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
- Field `crmToken` for `Owner`
- Field `externalInvoice` and `shortCode` for `Order`
## [1.0.0] - 2022-07-27

View file

@ -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)

View file

@ -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