makes expected deposit linking work.

This commit is contained in:
2022-01-13 08:08:20 -08:00
parent f27e5aacdf
commit d6211c778b
9 changed files with 181 additions and 93 deletions

View File

@@ -1,6 +1,27 @@
(ns auto-ap.datomic.migrate.sales
(:require [datomic.api :as d]
[auto-ap.datomic :refer [uri]]))
(:require [datomic.api :as d]))
(defn backfill-status [conn]
(let [db (d/db conn)
pendings (->>
(d/q '[:find [?ed ...]
:where [?ed :expected-deposit/date]
(not [_ :transaction/expected-deposit ?ed])
(not [?ed :expected-deposit/status])]
db)
(map (fn [ed]
{:db/id ed
:expected-deposit/status :expected-deposit-status/pending})))
cleared (->>
(d/q '[:find [?ed ...]
:where [?ed :expected-deposit/date]
[_ :transaction/expected-deposit ?ed]
(not [?ed :expected-deposit/status])]
db)
(map (fn [ed]
{:db/id ed
:expected-deposit/status :expected-deposit-status/cleared})))]
[(into pendings cleared)]))
(def norms-map {:add-orders {:txes [[{:db/ident :sales-order/external-id
:db/doc "The client for the sale"
@@ -206,6 +227,7 @@
:db/doc "If this transaction is a deposit, the deposit that we anticipated"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}]]}
:add-vendor-for-sales-stuff {:txes [[{:db/ident :expected-deposit/vendor
:db/doc "Which vendor is this deposit for? CCP Square?"
:db/valueType :db.type/ref
@@ -218,6 +240,12 @@
:db/doc "Which vendor is this refund for? CCP Square?"
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one}]]}
:backfill-status {:txes-fn `backfill-status
:requires [:add-expected-deposit-status
:add-expected-deposits
:add-sales-date
:add-vendor-for-sales-stuff
:add-orders]}
:add-refund-type {:txes [[{:db/ident :sales-refund/type
:db/doc "The type of refund"
:db/valueType :db.type/string