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 upsertOrder o = do
let order = val $ updateOrderTotals o let order = val $ updateOrderTotals o
case order of case order of
Doc d -> Doc d -> upsert (select ["_id" =: q_id o] "orders") d
if isJust (q_id o) _ -> return ()
then upsert (select ["_id" =: q_id o] "orders") d
else insert_ "orders" d 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 () _ -> return ()
-- | Function to update order totals from items -- | Function to update order totals from items

View file

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