Don't import the wrong refunds

This commit is contained in:
2021-08-27 08:09:22 -07:00
parent 98d1dac0b8
commit 8b0bc6fdfa
2 changed files with 12 additions and 14 deletions

View File

@@ -3,7 +3,7 @@
:with ?s
:in $
:where
[?s :sales-order/client [:client/code "NGRV"]]
[?s :sales-order/client [:client/code "{{customer}}"]]
[?s :sales-order/date ?d]
[?s :sales-order/total ?total]
[?s :sales-order/tax ?tax]
@@ -15,14 +15,13 @@
[(auto-ap.time/localize ?d2) ?d3]
[(auto-ap.time/unparse-local ?d3 auto-ap.time/normal-date) ?d4]
]
a15e4880-e288-48e1-8249-6f67de9979c6
# Sales Categories
[:find ?d4 ?n ?n2 (sum ?total) (sum ?tax) (sum ?discount)
:with ?s ?li
:in $
:where
[?s :sales-order/client [:client/code "NGRV"]]
[?s :sales-order/client [:client/code "{{customer}}"]]
[?s :sales-order/date ?d]
[?s :sales-order/line-items ?li]
[?li :order-line-item/category ?n]
@@ -34,13 +33,12 @@ a15e4880-e288-48e1-8249-6f67de9979c6
[(auto-ap.time/localize ?d2) ?d3]
[(auto-ap.time/unparse-local ?d3 auto-ap.time/normal-date) ?d4]
]
a4179936-9a3e-4116-aa56-f7616e16f39f
# Expected Deposits
[:find ?d4 ?t ?f
:in $
:where
[?c :client/code "NGRV"]
[?c :client/code "{{customer}}"]
[?s :expected-deposit/client ?c]
[?s :expected-deposit/total ?t]
[?s :expected-deposit/fee ?f]
@@ -49,33 +47,33 @@ a4179936-9a3e-4116-aa56-f7616e16f39f
[(auto-ap.time/localize ?d2) ?d3]
[(auto-ap.time/unparse-local ?d3 auto-ap.time/normal-date) ?d4]
]
721af203-47af-487a-b4e0-476d4725a852
# Tenders
[:find ?d4 ?type (sum ?total) (sum ?tip)
[:find ?d4 ?type ?p2 (sum ?total) (sum ?tip)
:with ?charge
:in $
:where
[?c :client/code "NGRV"]
:in $
:where
[?c :client/code "{{customer}}"]
[?s :sales-order/client ?c]
[?s :sales-order/charges ?charge]
[?charge :charge/type-name ?type]
[?charge :charge/total ?total]
[?charge :charge/tip ?tip]
[(get-else $ ?charge :charge/processor :na) ?ccp]
[(get-else $ ?ccp :db/ident :na) ?p]
[(name ?p) ?p2]
[?s :sales-order/date ?date]
[(clj-time.coerce/to-date-time ?date) ?d2]
[(auto-ap.time/localize ?d2) ?d3]
[(auto-ap.time/unparse-local ?d3 auto-ap.time/normal-date) ?d4]
]
650da228-a427-4f58-8426-6d4e9c3a3658
# Refunds
[:find ?d4 (sum ?total) (sum ?fee)
:with ?r
:in $
:where
[?r :sales-refund/client [:client/code "NGRV"]]
[?r :sales-refund/client [:client/code "{{customer}}"]]
[?r :sales-refund/total ?total]
[?r :sales-refund/fee ?fee]
[?r :sales-refund/date ?date]
@@ -83,4 +81,3 @@ a4179936-9a3e-4116-aa56-f7616e16f39f
[(auto-ap.time/localize ?d2) ?d3]
[(auto-ap.time/unparse-local ?d3 auto-ap.time/normal-date) ?d4]
]
e6330966-697a-47e3-8223-f685b4f8792b

View File

@@ -312,6 +312,7 @@
(log/warn "Retrying after failure " ex)
(if (> try-count 4) false true))})))]
(->> refunds
(filter (fn [r] (= "COMPLETED" (:status r))))
(map (fn [r]
(let [[client location] (location_id->client-location l)]
#:sales-refund {:external-id (str "square/refund/" (:id r))