works to fill gaps.
This commit is contained in:
@@ -18,7 +18,6 @@
|
|||||||
(map :a)
|
(map :a)
|
||||||
(map namespace)
|
(map namespace)
|
||||||
set)]
|
set)]
|
||||||
(println namespaces changes)
|
|
||||||
(cond (namespaces "invoice" ) [[:invoice e]]
|
(cond (namespaces "invoice" ) [[:invoice e]]
|
||||||
(namespaces "invoice-expense-account" ) [[:invoice (:db/id (:invoice/_expense-accounts entity))]]
|
(namespaces "invoice-expense-account" ) [[:invoice (:db/id (:invoice/_expense-accounts entity))]]
|
||||||
(namespaces "transaction-account" ) [[:transaction (:db/id (:transaction/_accounts entity))]]
|
(namespaces "transaction-account" ) [[:transaction (:db/id (:transaction/_accounts entity))]]
|
||||||
|
|||||||
@@ -77,21 +77,22 @@
|
|||||||
(log/warn "couldn't look up" i)
|
(log/warn "couldn't look up" i)
|
||||||
"Uncategorized"))))
|
"Uncategorized"))))
|
||||||
|
|
||||||
(defn pc [d] {"query" {"filter" {"date_time_filter"
|
(defn pc [start end]
|
||||||
{
|
{"query" {"filter" {"date_time_filter"
|
||||||
"created_at" {
|
{
|
||||||
"start_at" (f/unparse (f/formatter "YYYY-MM-dd'T'HH:mm:ssZZ") (time/to-time-zone (coerce/to-date-time d) (time/time-zone-for-id "America/Los_Angeles")))
|
"created_at" {
|
||||||
"end_at" (f/unparse (f/formatter "YYYY-MM-dd'T'HH:mm:ssZZ") (time/to-time-zone (time/plus (coerce/to-date-time d) (time/days 1)) (time/time-zone-for-id "America/Los_Angeles")))
|
"start_at" (f/unparse (f/formatter "YYYY-MM-dd'T'HH:mm:ssZZ") start)
|
||||||
}
|
"end_at" (f/unparse (f/formatter "YYYY-MM-dd'T'HH:mm:ssZZ") end)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
||||||
"sort" {
|
"sort" {
|
||||||
"sort_field" "CREATED_AT"
|
"sort_field" "CREATED_AT"
|
||||||
"sort_order" "DESC"
|
"sort_order" "DESC"
|
||||||
}}})
|
}}})
|
||||||
|
|
||||||
(defn get-order
|
(defn get-order
|
||||||
([client location order-id]
|
([client location order-id]
|
||||||
@@ -103,33 +104,33 @@
|
|||||||
)]
|
)]
|
||||||
result)))
|
result)))
|
||||||
|
|
||||||
(defn continue-search [client location d cursor]
|
(defn continue-search [client location start end cursor]
|
||||||
(log/info "Continuing search for" cursor)
|
(log/info "Continuing search for" cursor)
|
||||||
(let [result (->> (client/post "https://connect.squareup.com/v2/orders/search"
|
(let [result (->> (client/post "https://connect.squareup.com/v2/orders/search"
|
||||||
{:headers (client-base-headers client)
|
{:headers (client-base-headers client)
|
||||||
:body (json/write-str (cond-> {"location_ids" [(:square-location/square-id location)]
|
:body (json/write-str (cond-> {"location_ids" [(:square-location/square-id location)]
|
||||||
"limit" 10000
|
"limit" 10000
|
||||||
"cursor" cursor}
|
"cursor" cursor}
|
||||||
d (merge (pc d))))
|
start (merge (pc start end))))
|
||||||
:as :json})
|
:as :json})
|
||||||
:body)]
|
:body)]
|
||||||
(log/info "found " (count (:orders result)))
|
(log/info "found " (count (:orders result)))
|
||||||
(if (not-empty (:cursor result))
|
(if (not-empty (:cursor result))
|
||||||
(concat (:orders result) (continue-search client location d (:cursor result)))
|
(concat (:orders result) (continue-search client location start end (:cursor result)))
|
||||||
(:orders result))))
|
(:orders result))))
|
||||||
|
|
||||||
(defn search
|
(defn search
|
||||||
([client location d]
|
([client location start end]
|
||||||
(log/info "Searching for" (:square-location/client-location location))
|
(log/info "Searching for" (:square-location/client-location location))
|
||||||
(let [result (->> (client/post "https://connect.squareup.com/v2/orders/search"
|
(let [result (->> (client/post "https://connect.squareup.com/v2/orders/search"
|
||||||
{:headers (client-base-headers client)
|
{:headers (client-base-headers client)
|
||||||
:body (json/write-str (cond-> {"location_ids" [(:square-location/square-id location)] "limit" 10000}
|
:body (json/write-str (cond-> {"location_ids" [(:square-location/square-id location)] "limit" 10000}
|
||||||
d (merge (pc d))))
|
start (merge (pc start end))))
|
||||||
:as :json})
|
:as :json})
|
||||||
:body)]
|
:body)]
|
||||||
(log/info "found " (count (:orders result)))
|
(log/info "found " (count (:orders result)))
|
||||||
(if (not-empty (:cursor result))
|
(if (not-empty (:cursor result))
|
||||||
(concat (:orders result) (continue-search client location d (:cursor result)))
|
(concat (:orders result) (continue-search client location start end (:cursor result)))
|
||||||
(:orders result)))))
|
(:orders result)))))
|
||||||
|
|
||||||
|
|
||||||
@@ -205,9 +206,9 @@
|
|||||||
|
|
||||||
(defn daily-results
|
(defn daily-results
|
||||||
([client location]
|
([client location]
|
||||||
(daily-results client location nil))
|
(daily-results client location (time/plus (time/now) (time/days -3)) (time/now)))
|
||||||
([client location d]
|
([client location start end]
|
||||||
(let [search-results (search client location d)
|
(let [search-results (search client location start end)
|
||||||
koala-production-ids (->> search-results
|
koala-production-ids (->> search-results
|
||||||
(filter #(= "koala-production" (:name (:source %))))
|
(filter #(= "koala-production" (:name (:source %))))
|
||||||
(map :id)
|
(map :id)
|
||||||
@@ -372,8 +373,8 @@
|
|||||||
([client ]
|
([client ]
|
||||||
(doseq [square-location (:client/square-locations client)
|
(doseq [square-location (:client/square-locations client)
|
||||||
:when (:square-location/client-location square-location)]
|
:when (:square-location/client-location square-location)]
|
||||||
(upsert client square-location (atime/unparse-local (time/now) atime/iso-date))))
|
(upsert client square-location (time/plus (time/now) (time/days -3)) (time/now))))
|
||||||
([client location d]
|
([client location start end]
|
||||||
(lc/with-context {:source "Square loading"}
|
(lc/with-context {:source "Square loading"}
|
||||||
(try
|
(try
|
||||||
(let [existing (->> (d/query {:query {:find ['?external-id]
|
(let [existing (->> (d/query {:query {:find ['?external-id]
|
||||||
@@ -385,7 +386,7 @@
|
|||||||
set)
|
set)
|
||||||
_ (log/info (count existing) "Sales orders already exist")
|
_ (log/info (count existing) "Sales orders already exist")
|
||||||
to-create (filter #(not (existing (:sales-order/external-id %)))
|
to-create (filter #(not (existing (:sales-order/external-id %)))
|
||||||
(daily-results client location d))]
|
(daily-results client location start end))]
|
||||||
(doseq [x (partition-all 20 to-create)]
|
(doseq [x (partition-all 20 to-create)]
|
||||||
(log/info "Loading " (count x))
|
(log/info "Loading " (count x))
|
||||||
@(d/transact conn x)))
|
@(d/transact conn x)))
|
||||||
|
|||||||
Reference in New Issue
Block a user