Fixes issue with stepping on each others toes when importing invoices

This commit is contained in:
2024-02-07 21:51:01 -08:00
parent 8f3eff4b01
commit 56215621c9
2 changed files with 100 additions and 94 deletions

View File

@@ -149,6 +149,7 @@
:uberjar
{:java-cmd "/usr/lib/jvm/java-11-openjdk/bin/java"
:prep-tasks ["fig:min" ]
:aot [auto-ap.server auto-ap.time clj-time.core clj-time.coerce clj-time.format clojure.tools.logging.impl ]
:dependencies [[com.bhauman/figwheel-main "0.2.18" :exclusions [org.clojure/clojurescript
ring
ring/ring-core
@@ -180,9 +181,6 @@
}
:main auto-ap.server
#_#_:aot [auto-ap.server auto-ap.time clj-time.core clj-time.coerce clj-time.format clojure.tools.logging.impl]
:uberjar-name "auto-ap.jar"
:test-paths ["test/clj"]
:test-selectors {:integration (fn [m]

View File

@@ -56,26 +56,35 @@
(first (d-invoices/get-graphql (assoc (<-graphql args)
:count Integer/MAX_VALUE)))))
(defn pending-invoices [invoices]
(->> (dc/q '[:find ?i
:in $ [?i ...]
:where [?i :invoice/import-status :import-status/pending]]
(dc/db conn)
invoices)
(map first)))
(defn reject-invoices [context {:keys [invoices]} _]
(assert-power-user (:id context))
(let [invoices (pending-invoices invoices)]
(doseq [i invoices]
(assert-can-see-client (:id context) (:db/id (:invoice/client (dc/pull (dc/db conn) [{:invoice/client [:db/id]}] i)))))
(let [transactions (mapcat (fn [i] [[:db/retractEntity i]])
invoices)]
(audit-transact transactions (:id context))
invoices))
invoices)))
(defn approve-invoices [context {:keys [invoices]} _]
(assert-power-user (:id context))
(let [invoices (pending-invoices invoices)]
(doseq [i invoices
:let [invoice (dc/pull (dc/db conn) [{:invoice/client [:db/id]}
:invoice/date]
i)]]
:let [invoice (dc/pull (dc/db conn) '[{:invoice/client [:db/id]}
:invoice/date] i)]]
(assert-can-see-client (:id context) (-> invoice :invoice/client :db/id))
(assert-not-locked (-> invoice :invoice/client :db/id) (-> invoice :invoice/date)))
(let [transactions (map (fn [i] [:upsert-invoice {:db/id i :invoice/import-status :import-status/imported}]) invoices)]
(audit-transact transactions (:id context))
invoices))
invoices)))
(defn assert-no-conflicting [{:keys [invoice_number client_id vendor_id]}]
(when-not vendor_id
@@ -291,8 +300,7 @@
[(>= ?d ?lu)]]
(dc/db conn)
all-ids)
(map first))
]
(map first))]
(alog/info ::void-payments :count (count voidable-cash-payments))
(gq-checks/void-payments-internal voidable-cash-payments (:id context))