fixes ezcater upsert

This commit is contained in:
2022-12-05 11:46:56 -08:00
parent a7a0867dc2
commit 59c62439ab

View File

@@ -275,10 +275,10 @@
(update-in [:sales-order/charges 0 :charge/date] coerce/to-date))]))
(defn upsert-recent []
(let [last-monday (coerce/to-date (time/plus (first (->> (time/today)
(iterate #(time/plus % (time/days -1)))
(filter #(= 1 (time/day-of-week %)))))
(time/days 1)))
(let [last-sunday (coerce/to-date (time/plus (second (->> (time/today)
(iterate #(time/plus % (time/days -1)))
(filter #(= 7 (time/day-of-week %)))))
(time/days 1)))
orders-to-update (doall (for [[order uuid] (d/q '[:find ?eid ?uuid
:in $ ?start
:where [?e :sales-order/vendor :vendor/ccp-ezcater]
@@ -290,7 +290,7 @@
[?l :ezcater-location/caterer ?c2]
[?c2 :ezcater-caterer/uuid ?uuid]]
(d/db conn)
last-monday)
last-sunday)
:let [_ (log/info "Considering updating " order)
id (last (str/split order #"/"))
id (str/join "-" (drop 2 (str/split order #"-")))
@@ -310,7 +310,11 @@
{:sales-order/charges [:charge/tax
:charge/tip
:charge/total
:charge/external-id]}]
:charge/external-id]
:sales-order/line-items [:order-line-item/external-id
:order-line-item/total
:order-line-item/tax
:order-line-item/discount]}]
[:sales-order/external-id order])
updated-order (-> (order->sales-order ezcater-order)
@@ -320,7 +324,14 @@
:sales-order/tip
:sales-order/discount
:sales-order/charges
:sales-order/external-id})
:sales-order/external-id
:sales-order/line-items})
(update :sales-order/line-items
(fn [c]
(map #(select-keys % #{:order-line-item/external-id
:order-line-item/total
:order-line-item/tax
:order-line-item/discount}) c)))
(update :sales-order/charges (fn [c]
(map #(select-keys % #{:charge/tax :charge/tip :charge/total
:charge/external-id}) c))))]
@@ -328,5 +339,8 @@
:when (not= updated-order extant-order)]
updated-order))]
(log/info "Found these orders to update:" orders-to-update)
@(d/transact conn orders-to-update)))