avoids duplicate invoices atomic, prevents query that causes warnings.

This commit is contained in:
2021-11-17 21:50:12 -08:00
parent f345788284
commit fe48373943
4 changed files with 79 additions and 37 deletions

View File

@@ -79,6 +79,24 @@
(seq vs) (conj {:db/id e
a vs})))})}]])
(defn propose-invoice-fn [conn]
[[{:db/ident :propose-invoice
:db/doc "Adds an invoice if it's not found"
:db/fn (d/function '{:lang "clojure"
:params [db invoice]
:code (let [existing? (boolean (seq (d/query {:query {:find ['?i]
:in ['$ '?invoice-number '?client '?vendor]
:where ['[?i :invoice/invoice-number ?invoice-number]
'[?i :invoice/client ?client]
'[?i :invoice/vendor ?vendor]
'(not [?i :invoice/status :invoice-status/voided])
]}
:args [db (:invoice/invoice-number invoice) (:invoice/client invoice) (:invoice/vendor invoice)]})))]
(if existing?
[]
[invoice]))})}]])
(defn add-include-in-reports [conn]
(let [existing-accounts (->> (d/query {:query {:find ['?e]
:in ['$]
@@ -335,7 +353,13 @@
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-power-user-schema {:txes [[{:db/ident :user-role/power-user}]]}
:auto-ap/add-transaction-date-index {:txes [[{:db/ident :transaction/date
:db/index true}]]}}
:db/index true}]]}
:auto-ap/add-invoice-index {:txes [[{:db/ident :invoice/invoice-number
:db/index true}]]
:depends-on [:auto-ap/base-schema]}
:auto-ap/add-propose-invoice {:txes-fn `propose-invoice-fn
:depends-on [:auto-ap/base-schema]}}