Correct duplicate Xero orders

This commit is contained in:
Rene Vergara 2022-08-21 16:59:23 -05:00
parent acf2103f0c
commit 7240dd1b87
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2
2 changed files with 9 additions and 5 deletions

View file

@ -185,10 +185,14 @@ upsertOrder :: ZGoOrder -> Action IO ()
upsertOrder o = do
let order = val $ updateOrderTotals o
case order of
Doc d ->
if isJust (q_id o)
then upsert (select ["_id" =: q_id o] "orders") d
else insert_ "orders" d
Doc d -> upsert (select ["_id" =: q_id o] "orders") d
_ -> return ()
upsertXeroOrder :: ZGoOrder -> Action IO ()
upsertXeroOrder o = do
let order = val $ updateOrderTotals o
case order of
Doc d -> upsert (select ["externalInvoice" =: qexternalInvoice o, "shortCode" =: qshortCode o] "orders") d
_ -> return ()
-- | Function to update order totals from items

View file

@ -752,7 +752,7 @@ routes pipe config = do
post "/api/orderx" $ do
newOrder <- jsonData
let q = payload (newOrder :: Payload ZGoOrder)
_ <- liftIO $ run (upsertOrder q)
_ <- liftIO $ run (upsertXeroOrder q)
myOrder <-
liftIO $
run (findXeroOrder (qaddress q) (qexternalInvoice q) (qshortCode q))