Fixes issue with stepping on each others toes when importing invoices
This commit is contained in:
@@ -149,6 +149,7 @@
|
|||||||
:uberjar
|
:uberjar
|
||||||
{:java-cmd "/usr/lib/jvm/java-11-openjdk/bin/java"
|
{:java-cmd "/usr/lib/jvm/java-11-openjdk/bin/java"
|
||||||
:prep-tasks ["fig:min" ]
|
: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
|
:dependencies [[com.bhauman/figwheel-main "0.2.18" :exclusions [org.clojure/clojurescript
|
||||||
ring
|
ring
|
||||||
ring/ring-core
|
ring/ring-core
|
||||||
@@ -180,9 +181,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
:main auto-ap.server
|
: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"
|
:uberjar-name "auto-ap.jar"
|
||||||
:test-paths ["test/clj"]
|
:test-paths ["test/clj"]
|
||||||
:test-selectors {:integration (fn [m]
|
:test-selectors {:integration (fn [m]
|
||||||
|
|||||||
@@ -56,26 +56,35 @@
|
|||||||
(first (d-invoices/get-graphql (assoc (<-graphql args)
|
(first (d-invoices/get-graphql (assoc (<-graphql args)
|
||||||
:count Integer/MAX_VALUE)))))
|
: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]} _]
|
(defn reject-invoices [context {:keys [invoices]} _]
|
||||||
(assert-power-user (:id context))
|
(assert-power-user (:id context))
|
||||||
|
(let [invoices (pending-invoices invoices)]
|
||||||
(doseq [i invoices]
|
(doseq [i invoices]
|
||||||
(assert-can-see-client (:id context) (:db/id (:invoice/client (dc/pull (dc/db conn) [{:invoice/client [:db/id]}] i)))))
|
(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]])
|
(let [transactions (mapcat (fn [i] [[:db/retractEntity i]])
|
||||||
invoices)]
|
invoices)]
|
||||||
(audit-transact transactions (:id context))
|
(audit-transact transactions (:id context))
|
||||||
invoices))
|
invoices)))
|
||||||
|
|
||||||
(defn approve-invoices [context {:keys [invoices]} _]
|
(defn approve-invoices [context {:keys [invoices]} _]
|
||||||
(assert-power-user (:id context))
|
(assert-power-user (:id context))
|
||||||
|
(let [invoices (pending-invoices invoices)]
|
||||||
(doseq [i invoices
|
(doseq [i invoices
|
||||||
:let [invoice (dc/pull (dc/db conn) [{:invoice/client [:db/id]}
|
:let [invoice (dc/pull (dc/db conn) '[{:invoice/client [:db/id]}
|
||||||
:invoice/date]
|
:invoice/date] i)]]
|
||||||
i)]]
|
|
||||||
(assert-can-see-client (:id context) (-> invoice :invoice/client :db/id))
|
(assert-can-see-client (:id context) (-> invoice :invoice/client :db/id))
|
||||||
(assert-not-locked (-> invoice :invoice/client :db/id) (-> invoice :invoice/date)))
|
(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)]
|
(let [transactions (map (fn [i] [:upsert-invoice {:db/id i :invoice/import-status :import-status/imported}]) invoices)]
|
||||||
(audit-transact transactions (:id context))
|
(audit-transact transactions (:id context))
|
||||||
invoices))
|
invoices)))
|
||||||
|
|
||||||
(defn assert-no-conflicting [{:keys [invoice_number client_id vendor_id]}]
|
(defn assert-no-conflicting [{:keys [invoice_number client_id vendor_id]}]
|
||||||
(when-not vendor_id
|
(when-not vendor_id
|
||||||
@@ -291,8 +300,7 @@
|
|||||||
[(>= ?d ?lu)]]
|
[(>= ?d ?lu)]]
|
||||||
(dc/db conn)
|
(dc/db conn)
|
||||||
all-ids)
|
all-ids)
|
||||||
(map first))
|
(map first))]
|
||||||
]
|
|
||||||
(alog/info ::void-payments :count (count voidable-cash-payments))
|
(alog/info ::void-payments :count (count voidable-cash-payments))
|
||||||
(gq-checks/void-payments-internal voidable-cash-payments (:id context))
|
(gq-checks/void-payments-internal voidable-cash-payments (:id context))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user