From a122c45b03328d4dbb59a0f3542834c4bb8767fa Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Wed, 29 Jun 2022 06:55:01 -0700 Subject: [PATCH] make orders upsertable. --- src/clj/auto_ap/datomic/migrate/sales.clj | 5 +++++ src/clj/auto_ap/square/core.clj | 25 ++++++++++++----------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/clj/auto_ap/datomic/migrate/sales.clj b/src/clj/auto_ap/datomic/migrate/sales.clj index 66342905..f3f6c7c2 100644 --- a/src/clj/auto_ap/datomic/migrate/sales.clj +++ b/src/clj/auto_ap/datomic/migrate/sales.clj @@ -251,6 +251,11 @@ :db/valueType :db.type/string :db/cardinality :db.cardinality/one :db/unique :db.unique/identity}]]} + :add-line-item-id2 {:txes [[{:db/ident :order-line-item/external-id + :db/doc "An Id that links to square etc" + :db/valueType :db.type/string + :db/cardinality :db.cardinality/one + :db/unique :db.unique/identity}]]} :add-expected-depsoit-link {:txes [[{:db/ident :expected-deposit/charges :db/doc "charges for the deposit" :db/valueType :db.type/ref diff --git a/src/clj/auto_ap/square/core.clj b/src/clj/auto_ap/square/core.clj index b34fd12b..ee4054a9 100644 --- a/src/clj/auto_ap/square/core.clj +++ b/src/clj/auto_ap/square/core.clj @@ -178,8 +178,8 @@ (remove-nils #:charge {:type-name (:type t) - :external-id (when (:payment_id t) - (str "square/charge/" (:payment_id t))) + :external-id (when (:id t) + (str "square/charge/" (:id t))) :processor (condp = (some-> (:note t) str/lower-case) "doordash" :ccp-processor/doordash "dd" :ccp-processor/doordash @@ -196,16 +196,17 @@ :total (amount->money (:amount_money t)) :tip (amount->money (:tip_money t))})))) :line-items (->> (:line_items order) - (map (fn [li] - (remove-nils - #:order-line-item - {:item-name (:name li) - :category (if (= "GIFT_CARD" (:item_type li)) - "Gift Card" - (item-id->category-name client (:catalog_object_id li))) - :total (amount->money (:total_money li)) - :tax (amount->money (:total_tax_money li)) - :discount (amount->money (:total_discount_money li))}))))})) + (map-indexed (fn [i li] + (remove-nils + #:order-line-item + {:external-id (str "square/order/" (:client/code client) "-" (:square-location/client-location location) "-" (:id order) "-" i) + :item-name (:name li) + :category (if (= "GIFT_CARD" (:item_type li)) + "Gift Card" + (item-id->category-name client (:catalog_object_id li))) + :total (amount->money (:total_money li)) + :tax (amount->money (:total_tax_money li)) + :discount (amount->money (:total_discount_money li))}))))})) (defn daily-results ([client location]