(cloud) Saving things now update the search index
This commit is contained in:
@@ -35,7 +35,8 @@
|
|||||||
[config.core :refer [env]]
|
[config.core :refer [env]]
|
||||||
[clj-time.coerce :as coerce]
|
[clj-time.coerce :as coerce]
|
||||||
[datomic.api :as dc]
|
[datomic.api :as dc]
|
||||||
[digest])
|
[digest]
|
||||||
|
[auto-ap.solr :as solr])
|
||||||
(:import
|
(:import
|
||||||
(java.io ByteArrayOutputStream)
|
(java.io ByteArrayOutputStream)
|
||||||
(java.text DecimalFormat)
|
(java.text DecimalFormat)
|
||||||
@@ -414,11 +415,12 @@
|
|||||||
(make-pdfs (filter #(and (= :payment-type/check (:payment/type %))
|
(make-pdfs (filter #(and (= :payment-type/check (:payment/type %))
|
||||||
(> (:payment/amount %) 0.0))
|
(> (:payment/amount %) 0.0))
|
||||||
checks))))
|
checks))))
|
||||||
(audit-transact (map #(if (map? %)
|
(let [result (audit-transact (map #(if (map? %)
|
||||||
(dissoc % :payment/pdf-data)
|
(dissoc % :payment/pdf-data)
|
||||||
%) checks ) id)
|
%) checks ) id)]
|
||||||
|
|
||||||
|
(doseq [i (:tempids result)]
|
||||||
|
(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)
|
||||||
(mu/trace ::merge-pdfs
|
(mu/trace ::merge-pdfs
|
||||||
@@ -475,14 +477,16 @@
|
|||||||
0
|
0
|
||||||
invoice-payment-lookup)]
|
invoice-payment-lookup)]
|
||||||
|
|
||||||
(audit-transact
|
(let [result (audit-transact
|
||||||
(into [(assoc base-payment
|
(into [(assoc base-payment
|
||||||
:payment/type :payment-type/check
|
:payment/type :payment-type/check
|
||||||
:payment/status :payment-status/pending
|
:payment/status :payment-status/pending
|
||||||
:payment/check-number (:check_number args)
|
:payment/check-number (:check_number args)
|
||||||
: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)]
|
||||||
|
(solr/touch-with-ledger i)))
|
||||||
(->graphql
|
(->graphql
|
||||||
{:s3-url nil
|
{:s3-url nil
|
||||||
:invoices (d-invoices/get-multi (map :invoice_id (:invoice_payments args)))})))
|
:invoices (d-invoices/get-multi (map :invoice_id (:invoice_payments args)))})))
|
||||||
@@ -648,9 +652,11 @@
|
|||||||
:payment/type :payment-type/balance-credit
|
:payment/type :payment-type/balance-credit
|
||||||
:payment/status :payment-status/cleared}]
|
:payment/status :payment-status/cleared}]
|
||||||
|
|
||||||
(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)]
|
||||||
|
(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))})))
|
||||||
|
|
||||||
(def objects
|
(def objects
|
||||||
|
|||||||
@@ -22,7 +22,8 @@
|
|||||||
[clj-time.core :as time]
|
[clj-time.core :as time]
|
||||||
[clojure.tools.logging :as log]
|
[clojure.tools.logging :as log]
|
||||||
[com.brunobonacci.mulog :as mu]
|
[com.brunobonacci.mulog :as mu]
|
||||||
[datomic.api :as dc]))
|
[datomic.api :as dc]
|
||||||
|
[auto-ap.solr :as solr]))
|
||||||
|
|
||||||
(defn ->graphql [invoice user ]
|
(defn ->graphql [invoice user ]
|
||||||
(if (= "admin" (:user/role user))
|
(if (= "admin" (:user/role user))
|
||||||
@@ -176,6 +177,7 @@
|
|||||||
(assert-invoice-amounts-add-up in)
|
(assert-invoice-amounts-add-up in)
|
||||||
|
|
||||||
(let [transaction-result (audit-transact [(add-invoice-transaction in)] (:id context))]
|
(let [transaction-result (audit-transact [(add-invoice-transaction in)] (:id context))]
|
||||||
|
(solr/touch-with-ledger (get-in transaction-result [:tempids "invoice"]))
|
||||||
(-> (d-invoices/get-by-id (get-in transaction-result [:tempids "invoice"]))
|
(-> (d-invoices/get-by-id (get-in transaction-result [:tempids "invoice"]))
|
||||||
(->graphql (:id context)))))
|
(->graphql (:id context)))))
|
||||||
|
|
||||||
@@ -231,6 +233,7 @@
|
|||||||
:invoice/scheduled-payment (coerce/to-date scheduled_payment)}]
|
:invoice/scheduled-payment (coerce/to-date scheduled_payment)}]
|
||||||
(audit-transact [[:upsert-invoice updated-invoice]]
|
(audit-transact [[:upsert-invoice updated-invoice]]
|
||||||
(:id context))
|
(:id context))
|
||||||
|
(solr/touch-with-ledger id)
|
||||||
(-> (d-invoices/get-by-id id)
|
(-> (d-invoices/get-by-id id)
|
||||||
(->graphql (:id context)))))
|
(->graphql (:id context)))))
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,8 @@
|
|||||||
[clojure.tools.logging :as log]
|
[clojure.tools.logging :as log]
|
||||||
[com.brunobonacci.mulog :as mu]
|
[com.brunobonacci.mulog :as mu]
|
||||||
[datomic.api :as dc]
|
[datomic.api :as dc]
|
||||||
[iol-ion.tx :refer [random-tempid]])
|
[iol-ion.tx :refer [random-tempid]]
|
||||||
|
[auto-ap.solr :as solr])
|
||||||
(:import
|
(:import
|
||||||
(org.apache.commons.codec.binary Base64)))
|
(org.apache.commons.codec.binary Base64)))
|
||||||
|
|
||||||
@@ -531,7 +532,8 @@
|
|||||||
#_(log/info (map :tx success))
|
#_(log/info (map :tx success))
|
||||||
(mu/trace ::success-tx
|
(mu/trace ::success-tx
|
||||||
[:count (count success)]
|
[:count (count success)]
|
||||||
(audit-transact-batch (map :tx success) (:id context)))
|
(doseq [n (:tempids (audit-transact-batch (map :tx success) (:id context)))]
|
||||||
|
(solr/touch n)))
|
||||||
|
|
||||||
{:successful (map (fn [x] {:external_id (:external_id x)}) success)
|
{:successful (map (fn [x] {:external_id (:external_id x)}) success)
|
||||||
:ignored (map (fn [x]
|
:ignored (map (fn [x]
|
||||||
|
|||||||
@@ -27,7 +27,8 @@
|
|||||||
[clojure.tools.logging :as log]
|
[clojure.tools.logging :as log]
|
||||||
[datomic.api :as dc]
|
[datomic.api :as dc]
|
||||||
[iol-ion.tx :refer [random-tempid]]
|
[iol-ion.tx :refer [random-tempid]]
|
||||||
[com.brunobonacci.mulog :as mu]))
|
[com.brunobonacci.mulog :as mu]
|
||||||
|
[auto-ap.solr :as solr]))
|
||||||
|
|
||||||
(def approval-status->graphql (ident->enum-f :transaction/approval-status))
|
(def approval-status->graphql (ident->enum-f :transaction/approval-status))
|
||||||
|
|
||||||
@@ -369,6 +370,7 @@
|
|||||||
:transaction/accounts (map transaction-account->entity accounts)
|
:transaction/accounts (map transaction-account->entity accounts)
|
||||||
:transaction/forecast-match forecast_match}]]
|
:transaction/forecast-match forecast_match}]]
|
||||||
(:id context))
|
(:id context))
|
||||||
|
(solr/touch-with-ledger id)
|
||||||
(-> (d-transactions/get-by-id id)
|
(-> (d-transactions/get-by-id id)
|
||||||
approval-status->graphql
|
approval-status->graphql
|
||||||
->graphql)))
|
->graphql)))
|
||||||
@@ -403,6 +405,7 @@
|
|||||||
:transaction-account/location "A"
|
:transaction-account/location "A"
|
||||||
:transaction-account/amount (Math/abs (:transaction/amount transaction))}]}]])
|
:transaction-account/amount (Math/abs (:transaction/amount transaction))}]}]])
|
||||||
(:id context)))
|
(:id context)))
|
||||||
|
(solr/touch-with-ledger transaction_id)
|
||||||
(-> (d-transactions/get-by-id transaction_id)
|
(-> (d-transactions/get-by-id transaction_id)
|
||||||
approval-status->graphql
|
approval-status->graphql
|
||||||
->graphql))
|
->graphql))
|
||||||
@@ -437,7 +440,7 @@
|
|||||||
(:db/id (:transaction/client transaction)))]
|
(:db/id (:transaction/client transaction)))]
|
||||||
(log/info "Adding a new payment" payment-tx)
|
(log/info "Adding a new payment" payment-tx)
|
||||||
(audit-transact payment-tx (:id context)))
|
(audit-transact payment-tx (:id context)))
|
||||||
|
(solr/touch-with-ledger transaction_id)
|
||||||
(-> (d-transactions/get-by-id transaction_id)
|
(-> (d-transactions/get-by-id transaction_id)
|
||||||
approval-status->graphql
|
approval-status->graphql
|
||||||
->graphql)))
|
->graphql)))
|
||||||
@@ -475,6 +478,7 @@
|
|||||||
(:db/id (:transaction/bank-account transaction))
|
(:db/id (:transaction/bank-account transaction))
|
||||||
(:db/id (:transaction/client transaction)))]
|
(:db/id (:transaction/client transaction)))]
|
||||||
(audit-transact payment-tx (:id context)))
|
(audit-transact payment-tx (:id context)))
|
||||||
|
(solr/touch-with-ledger transaction_id)
|
||||||
|
|
||||||
(-> (d-transactions/get-by-id transaction_id)
|
(-> (d-transactions/get-by-id transaction_id)
|
||||||
approval-status->graphql
|
approval-status->graphql
|
||||||
@@ -505,7 +509,7 @@
|
|||||||
(when (not (rm/rule-applies? transaction transaction-rule))
|
(when (not (rm/rule-applies? transaction transaction-rule))
|
||||||
(throw (ex-info "Transaction rule does not apply" {:validation-error "Transaction rule does not apply"
|
(throw (ex-info "Transaction rule does not apply" {:validation-error "Transaction rule does not apply"
|
||||||
:transaction-rule transaction-rule
|
:transaction-rule transaction-rule
|
||||||
:transaction transaction})))
|
:transaction transaction})))
|
||||||
|
|
||||||
(when (:transaction/payment transaction)
|
(when (:transaction/payment transaction)
|
||||||
|
|
||||||
@@ -520,6 +524,9 @@
|
|||||||
(-> t :transaction/client :client/locations))))])
|
(-> t :transaction/client :client/locations))))])
|
||||||
transactions)
|
transactions)
|
||||||
(:id context))
|
(:id context))
|
||||||
|
|
||||||
|
(doseq [n transactions]
|
||||||
|
(solr/touch-with-ledger (:db/id n)))
|
||||||
)
|
)
|
||||||
(transduce
|
(transduce
|
||||||
(comp
|
(comp
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
[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)
|
||||||
@@ -317,11 +318,13 @@
|
|||||||
:error :import-batch/error
|
:error :import-batch/error
|
||||||
:not-ready :import-batch/not-ready) inc))
|
:not-ready :import-batch/not-ready) inc))
|
||||||
(when (= :import action)
|
(when (= :import action)
|
||||||
(audit-transact [[:upsert-transaction (transaction->txs transaction bank-account rule-applying-function)]
|
(let [result (audit-transact [[:upsert-transaction (transaction->txs transaction bank-account rule-applying-function)]
|
||||||
{:db/id import-id
|
{:db/id import-id
|
||||||
: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)]
|
||||||
|
(solr/touch-with-ledger n))))))
|
||||||
|
|
||||||
(get-stats [_]
|
(get-stats [_]
|
||||||
@stats)
|
@stats)
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
(ns auto-ap.solr
|
(ns auto-ap.solr
|
||||||
(:require
|
(:require
|
||||||
[auto-ap.datomic :refer [conn]]
|
[auto-ap.datomic :refer [conn pull-id]]
|
||||||
[clj-http.client :as client]
|
|
||||||
[clojure.data.json :as json]
|
|
||||||
[config.core :refer [env]]
|
|
||||||
[datomic.api :as dc]
|
|
||||||
[clj-time.coerce :as c]
|
|
||||||
[auto-ap.time :as atime]
|
[auto-ap.time :as atime]
|
||||||
[clojure.string :as str]))
|
[clj-http.client :as client]
|
||||||
|
[clj-time.coerce :as c]
|
||||||
|
[clojure.data.json :as json]
|
||||||
|
[clojure.string :as str]
|
||||||
|
[config.core :refer [env]]
|
||||||
|
[datomic.api :as dc]))
|
||||||
|
|
||||||
(def solr-uri (:solr-uri env))
|
(def solr-uri (:solr-uri env))
|
||||||
|
|
||||||
@@ -34,8 +34,7 @@
|
|||||||
"journal-entry"
|
"journal-entry"
|
||||||
|
|
||||||
:else
|
:else
|
||||||
(throw (ex-info "Trying to index unknown entity"
|
nil))))
|
||||||
{:id d}))))))
|
|
||||||
|
|
||||||
(defmethod datomic->solr "transaction" [d]
|
(defmethod datomic->solr "transaction" [d]
|
||||||
(let [i (dc/pull (dc/db conn) '[:db/id :transaction/description-original
|
(let [i (dc/pull (dc/db conn) '[:db/id :transaction/description-original
|
||||||
@@ -54,6 +53,9 @@
|
|||||||
"vendor_id" (-> i :transaction/vendor :db/id)
|
"vendor_id" (-> i :transaction/vendor :db/id)
|
||||||
"type" "transaction"}))
|
"type" "transaction"}))
|
||||||
|
|
||||||
|
(defmethod datomic->solr nil [d]
|
||||||
|
nil)
|
||||||
|
|
||||||
(defmethod datomic->solr "journal-entry" [d]
|
(defmethod datomic->solr "journal-entry" [d]
|
||||||
(let [i (dc/pull (dc/db conn) '[:db/id
|
(let [i (dc/pull (dc/db conn) '[:db/id
|
||||||
:journal-entry/amount
|
:journal-entry/amount
|
||||||
@@ -123,7 +125,7 @@
|
|||||||
:socket-timeout 30000
|
:socket-timeout 30000
|
||||||
:connection-timeout 30000
|
:connection-timeout 30000
|
||||||
:method "POST"
|
:method "POST"
|
||||||
:body (json/write-str (map datomic->solr xs))}))
|
:body (json/write-str (filter identity (map datomic->solr xs)))}))
|
||||||
|
|
||||||
(defn query [q]
|
(defn query [q]
|
||||||
(-> (client/post (str solr-uri "/solr/invoices/query")
|
(-> (client/post (str solr-uri "/solr/invoices/query")
|
||||||
@@ -145,3 +147,13 @@
|
|||||||
:method "POST"
|
:method "POST"
|
||||||
:body (json/write-str {"delete" {"query" "*:*"}})})
|
:body (json/write-str {"delete" {"query" "*:*"}})})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
(defn touch-with-ledger [i]
|
||||||
|
(index-documents [i
|
||||||
|
(pull-id (dc/db conn) [:journal-entry/original-entity i])]))
|
||||||
|
|
||||||
|
(defn touch [i]
|
||||||
|
(index-documents [i]))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user