Merge branch 'port-datomic-cloud' into try-tailwind

This commit is contained in:
2023-05-13 23:36:30 -07:00
6 changed files with 74 additions and 69 deletions

View File

@@ -6,24 +6,23 @@
(str (UUID/randomUUID))) (str (UUID/randomUUID)))
(defn get-line-items-after [db journal-entry] (defn get-line-items-after [db journal-entry]
(for [jel (:journal-entry/line-items journal-entry) (for [jel (:journal-entry/line-items journal-entry)
:let [next-jel (->> (dc/index-pull db {:index :avet next-jel (->> (dc/index-pull db {:index :avet
:selector [:db/id :journal-entry-line/client+account+location+date] :selector [:db/id :journal-entry-line/client+account+location+date]
:start [:journal-entry-line/client+account+location+date :start [:journal-entry-line/client+account+location+date
(:journal-entry-line/client+account+location+date jel) (:journal-entry-line/client+account+location+date jel)
(:db/id jel)] (:db/id jel)]
}) })
(take-while (fn line-must-match-client-account-location [result] (take-while (fn line-must-match-client-account-location [result]
(and (and
(= (take 3 (:journal-entry-line/client+account+location+date result)) (= (take 3 (:journal-entry-line/client+account+location+date result))
(take 3 (:journal-entry-line/client+account+location+date jel))) (take 3 (:journal-entry-line/client+account+location+date jel)))
(not= (:db/id jel) (not= (:db/id jel)
(:db/id result))) (:db/id result)))
)) ))
first (take 2))
:db/id)] :when next-jel]
:when next-jel] (:db/id next-jel)))
next-jel))
(def extant-read '[:db/id :journal-entry/date :journal-entry/client {:journal-entry/line-items [:journal-entry-line/account :journal-entry-line/location :db/id :journal-entry-line/client+account+location+date]}]) (def extant-read '[:db/id :journal-entry/date :journal-entry/client {:journal-entry/line-items [:journal-entry-line/account :journal-entry-line/location :db/id :journal-entry-line/client+account+location+date]}])

File diff suppressed because one or more lines are too long

View File

@@ -419,7 +419,7 @@
(dissoc % :payment/pdf-data) (dissoc % :payment/pdf-data)
%) checks ) id)] %) checks ) id)]
(doseq [i (:tempids result)] (doseq [[_ i] (:tempids result)]
(solr/touch-with-ledger i))) (solr/touch-with-ledger i)))
{:invoices (d-invoices/get-multi (map :invoice-id invoice-payments)) {:invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
:pdf-url (if (= type :payment-type/check) :pdf-url (if (= type :payment-type/check)
@@ -485,7 +485,7 @@
:payment/date (c/to-date (parse (:date args) iso-date)))] :payment/date (c/to-date (parse (:date args) iso-date)))]
(invoice-payments invoices invoice-payment-lookup)) (invoice-payments invoices invoice-payment-lookup))
(:id context))] (:id context))]
(doseq [i (:tempids result)] (doseq [[_ i] (:tempids result)]
(solr/touch-with-ledger i))) (solr/touch-with-ledger i)))
(->graphql (->graphql
{:s3-url nil {:s3-url nil
@@ -655,7 +655,7 @@
(let [result (audit-transact (-> [] (let [result (audit-transact (-> []
(conj payment) (conj payment)
(into (invoice-payments invoices invoice-amounts))) (:id context))] (into (invoice-payments invoices invoice-amounts))) (:id context))]
(doseq [n (:tempids result)] (doseq [[_ n] (:tempids result)]
(solr/touch-with-ledger n))) (solr/touch-with-ledger n)))
(->graphql {:invoices (d-invoices/get-multi (map :db/id invoices))}))) (->graphql {:invoices (d-invoices/get-multi (map :db/id invoices))})))

View File

@@ -6,6 +6,7 @@
[auto-ap.datomic.transaction-rules :as tr] [auto-ap.datomic.transaction-rules :as tr]
[auto-ap.datomic.transactions :as d-transactions] [auto-ap.datomic.transactions :as d-transactions]
[auto-ap.rule-matching :as rm] [auto-ap.rule-matching :as rm]
[auto-ap.solr :as solr]
[auto-ap.time :as atime] [auto-ap.time :as atime]
[auto-ap.utils :refer [dollars=]] [auto-ap.utils :refer [dollars=]]
[clj-time.coerce :as coerce] [clj-time.coerce :as coerce]
@@ -13,8 +14,7 @@
[clojure.core.cache :as cache] [clojure.core.cache :as cache]
[clojure.tools.logging :as log] [clojure.tools.logging :as log]
[datomic.api :as dc] [datomic.api :as dc]
[digest :as di] [digest :as di]))
[auto-ap.solr :as solr]))
(defn rough-match [client-id bank-account-id amount] (defn rough-match [client-id bank-account-id amount]
(if (and client-id bank-account-id amount) (if (and client-id bank-account-id amount)
@@ -219,7 +219,8 @@
:transaction/vendor (:db/id (:payment/vendor existing-payment)) :transaction/vendor (:db/id (:payment/vendor existing-payment))
:transaction/location "A" :transaction/location "A"
:transaction/accounts [#:transaction-account :transaction/accounts [#:transaction-account
{:account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"])) {:db/id (random-tempid)
:account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"]))
:location "A" :location "A"
:amount (Math/abs (double amount))}]))) :amount (Math/abs (double amount))}])))
@@ -234,7 +235,8 @@
(assoc transaction (assoc transaction
:transaction/expected-deposit {:db/id (:db/id expected-deposit) :transaction/expected-deposit {:db/id (:db/id expected-deposit)
:expected-deposit/status :expected-deposit-status/cleared} :expected-deposit/status :expected-deposit-status/cleared}
:transaction/accounts [{:transaction-account/account :account/ccp :transaction/accounts [{:db/id (random-tempid)
:transaction-account/account :account/ccp
:transaction-account/amount amount :transaction-account/amount amount
:transaction-account/location "A"}] :transaction-account/location "A"}]
:transaction/approval-status :transaction-approval-status/approved :transaction/approval-status :transaction-approval-status/approved
@@ -242,7 +244,7 @@
)))) ))))
(defn maybe-code [{:transaction/keys [client amount] :as transaction} apply-rules valid-locations] (defn maybe-code [{:transaction/keys [client amount] :as transaction} apply-rules valid-locations]
(when (seq (match-transaction-to-unpaid-invoices amount client)) (when-not (seq (match-transaction-to-unpaid-invoices amount client))
(apply-rules transaction valid-locations))) (apply-rules transaction valid-locations)))
(defn transaction->txs [transaction bank-account apply-rules] (defn transaction->txs [transaction bank-account apply-rules]
@@ -323,7 +325,7 @@
:import-batch/entry (:db/id transaction)}] :import-batch/entry (:db/id transaction)}]
{:user/name user {:user/name user
:user/role ":admin"})] :user/role ":admin"})]
(doseq [n (:tempids result)] (doseq [[_ n] (:tempids result)]
(solr/touch-with-ledger n)))))) (solr/touch-with-ledger n))))))
(get-stats [_] (get-stats [_]

View File

@@ -167,9 +167,12 @@
(->RealSolrClient (:solr-uri env)) (->RealSolrClient (:solr-uri env))
(->MockSolrClient ))) (->MockSolrClient )))
(defn touch-with-ledger [i] (defn touch-with-ledger [i]
(index-documents impl [i (index-documents impl [i [:journal-entry/original-entity i]]))
(pull-id (dc/db conn) [:journal-entry/original-entity i])]))
(defn touch [i] (defn touch [i]
(index-documents impl [i])) (index-documents impl [i]))

View File

@@ -28,42 +28,42 @@
:account/type :account-type/equity} :account/type :account-type/equity}
{:db/id "test-client" {:db/id "test-client"
:client/code "TEST"} :client/code "TEST"}
`(upsert-ledger {:db/id "journal-entry-1" [:upsert-ledger {:db/id "journal-entry-1"
:journal-entry/external-id "1" :journal-entry/external-id "1"
:journal-entry/date #inst "2022-01-01" :journal-entry/date #inst "2022-01-01"
:journal-entry/client "test-client" :journal-entry/client "test-client"
:journal-entry/line-items [{:db/id "line-1-1" :journal-entry/line-items [{:db/id "line-1-1"
:journal-entry-line/account "test-account-1" :journal-entry-line/account "test-account-1"
:journal-entry-line/location "A" :journal-entry-line/location "A"
:journal-entry-line/debit 10.0} :journal-entry-line/debit 10.0}
{:db/id "line-1-2" {:db/id "line-1-2"
:journal-entry-line/account "test-account-2" :journal-entry-line/account "test-account-2"
:journal-entry-line/location "A" :journal-entry-line/location "A"
:journal-entry-line/credit 10.0}]}) :journal-entry-line/credit 10.0}]}]
`(upsert-ledger {:db/id "journal-entry-2" [:upsert-ledger {:db/id "journal-entry-2"
:journal-entry/date #inst "2022-01-02" :journal-entry/date #inst "2022-01-02"
:journal-entry/external-id "2" :journal-entry/external-id "2"
:journal-entry/client "test-client" :journal-entry/client "test-client"
:journal-entry/line-items [{:db/id "line-2-1" :journal-entry/line-items [{:db/id "line-2-1"
:journal-entry-line/account "test-account-1" :journal-entry-line/account "test-account-1"
:journal-entry-line/location "A" :journal-entry-line/location "A"
:journal-entry-line/debit 50.0} :journal-entry-line/debit 50.0}
{:db/id "line-2-2" {:db/id "line-2-2"
:journal-entry-line/account "test-account-2" :journal-entry-line/account "test-account-2"
:journal-entry-line/location "A" :journal-entry-line/location "A"
:journal-entry-line/credit 50.0}]}) :journal-entry-line/credit 50.0}]}]
`(upsert-ledger {:db/id "journal-entry-3" [:upsert-ledger {:db/id "journal-entry-3"
:journal-entry/date #inst "2022-01-03" :journal-entry/date #inst "2022-01-03"
:journal-entry/external-id "3" :journal-entry/external-id "3"
:journal-entry/client "test-client" :journal-entry/client "test-client"
:journal-entry/line-items [{:db/id "line-3-1" :journal-entry/line-items [{:db/id "line-3-1"
:journal-entry-line/account "test-account-1" :journal-entry-line/account "test-account-1"
:journal-entry-line/location "A" :journal-entry-line/location "A"
:journal-entry-line/debit 150.0} :journal-entry-line/debit 150.0}
{:db/id "line-3-2" {:db/id "line-3-2"
:journal-entry-line/account "test-account-2" :journal-entry-line/account "test-account-2"
:journal-entry-line/location "A" :journal-entry-line/location "A"
:journal-entry-line/credit 150.0}]})]))] :journal-entry-line/credit 150.0}]}]]))]
(testing "should set running-balance on ledger entries missing them" (testing "should set running-balance on ledger entries missing them"
@@ -108,8 +108,9 @@
) )
(testing "changing a ledger entry should mark the line items as dirty" (testing "changing a ledger entry should mark the line items as dirty"
(d/transact conn (println "AFTER HERE")
[`(upsert-ledger ~{:db/id journal-entry-2 @(d/transact conn
[[:upsert-ledger {:db/id journal-entry-2
:journal-entry/date #inst "2022-01-02" :journal-entry/date #inst "2022-01-02"
:journal-entry/client test-client :journal-entry/client test-client
:journal-entry/external-id "2" :journal-entry/external-id "2"
@@ -120,7 +121,7 @@
{:db/id "line-2-2" {:db/id "line-2-2"
:journal-entry-line/account test-account-2 :journal-entry-line/account test-account-2
:journal-entry-line/location "A" :journal-entry-line/location "A"
:journal-entry-line/credit 50.0}]})]) :journal-entry-line/credit 50.0}]}]])
(is (= [true true] (is (= [true true]
(->> (d/pull (d/db conn) '[{:journal-entry/line-items [:journal-entry-line/dirty]}] journal-entry-2) (->> (d/pull (d/db conn) '[{:journal-entry/line-items [:journal-entry-line/dirty]}] journal-entry-2)
(:journal-entry/line-items) (:journal-entry/line-items)