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]
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
[datomic.api :as dc]
|
[datomic.api :as dc]
|
||||||
[auto-ap.solr :as solr]))
|
[auto-ap.solr :as solr]))
|
||||||
|
|
||||||
(defn ->graphql [invoice user ]
|
(defn ->graphql [invoice user]
|
||||||
(if (= "admin" (:user/role user))
|
(if (= "admin" (:user/role user))
|
||||||
(u/->graphql invoice)
|
(u/->graphql invoice)
|
||||||
(u/->graphql (if (:invoice/source-url-admin-only invoice)
|
(u/->graphql (if (:invoice/source-url-admin-only invoice)
|
||||||
@@ -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
|
||||||
@@ -141,7 +150,7 @@
|
|||||||
|
|
||||||
(when (and (= :allowance/denied
|
(when (and (= :allowance/denied
|
||||||
(:db/ident (:account/invoice-allowance account)))
|
(:db/ident (:account/invoice-allowance account)))
|
||||||
(not= (pull-ref (dc/db conn) :vendor/default-account vendor_id )
|
(not= (pull-ref (dc/db conn) :vendor/default-account vendor_id)
|
||||||
(:db/id account)))
|
(:db/id account)))
|
||||||
(let [err (str "Account isn't allowed for invoice use.")]
|
(let [err (str "Account isn't allowed for invoice use.")]
|
||||||
(throw (ex-info err
|
(throw (ex-info err
|
||||||
@@ -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))
|
||||||
|
|
||||||
@@ -377,7 +385,7 @@
|
|||||||
(let [invoice-id (:invoice_id args)
|
(let [invoice-id (:invoice_id args)
|
||||||
invoice (d-invoices/get-by-id invoice-id)
|
invoice (d-invoices/get-by-id invoice-id)
|
||||||
_ (assert-not-locked (:db/id (:invoice/client invoice)) (:invoice/date invoice))
|
_ (assert-not-locked (:db/id (:invoice/client invoice)) (:invoice/date invoice))
|
||||||
_ (assert-valid-expense-accounts (:expense_accounts args) (:db/id (:invoice/vendor invoice )))]
|
_ (assert-valid-expense-accounts (:expense_accounts args) (:db/id (:invoice/vendor invoice)))]
|
||||||
|
|
||||||
(audit-transact [[:upsert-invoice {:db/id invoice-id
|
(audit-transact [[:upsert-invoice {:db/id invoice-id
|
||||||
:invoice/expense-accounts (map
|
:invoice/expense-accounts (map
|
||||||
@@ -461,12 +469,12 @@
|
|||||||
:let [{:keys [:account/location :account/name]} (dc/pull (dc/db conn) [:account/location :account/name] (:account_id a))]]
|
:let [{:keys [:account/location :account/name]} (dc/pull (dc/db conn) [:account/location :account/name] (:account_id a))]]
|
||||||
(when (and location (not= location (:location a)))
|
(when (and location (not= location (:location a)))
|
||||||
(let [err (str "Account " name " uses location " (:location a) ", but is supposed to be " location)]
|
(let [err (str "Account " name " uses location " (:location a) ", but is supposed to be " location)]
|
||||||
(throw (ex-info err {:validation-error err}) )))
|
(throw (ex-info err {:validation-error err}))))
|
||||||
(when (and (not location)
|
(when (and (not location)
|
||||||
(not (get (into #{"Shared"} locations)
|
(not (get (into #{"Shared"} locations)
|
||||||
(:location a))))
|
(:location a))))
|
||||||
(let [err (str "Account " name " uses location " (:location a) ", but doesn't belong to the client.")]
|
(let [err (str "Account " name " uses location " (:location a) ", but doesn't belong to the client.")]
|
||||||
(throw (ex-info err {:validation-error err}) ))))
|
(throw (ex-info err {:validation-error err})))))
|
||||||
(alog/info ::bulk-code :count (count all-ids))
|
(alog/info ::bulk-code :count (count all-ids))
|
||||||
(audit-transact-batch
|
(audit-transact-batch
|
||||||
(map (fn [i]
|
(map (fn [i]
|
||||||
|
|||||||
Reference in New Issue
Block a user