added apply all rule.
This commit is contained in:
@@ -670,6 +670,7 @@
|
||||
|
||||
:match_transaction_rules {:type '(list :transaction)
|
||||
:args {:transaction_ids {:type '(list :id)}
|
||||
:all {:type 'Boolean}
|
||||
:transaction_rule_id {:type :id}}
|
||||
:resolve :mutation/match-transaction-rules}
|
||||
:void_invoice {:type :invoice
|
||||
|
||||
@@ -92,11 +92,12 @@
|
||||
(defn tr [z x]
|
||||
(re-find (re-pattern z) x))
|
||||
|
||||
(defn -test-transaction-rule [id {:keys [:transaction-rule/description :transaction-rule/note :transaction-rule/client :transaction-rule/bank-account :transaction-rule/amount-lte :transaction-rule/amount-gte :transaction-rule/dom-lte :transaction-rule/dom-gte :transaction-rule/yodlee-merchant]} include-coded?]
|
||||
(defn -test-transaction-rule [id {:keys [:transaction-rule/description :transaction-rule/note :transaction-rule/client :transaction-rule/bank-account :transaction-rule/amount-lte :transaction-rule/amount-gte :transaction-rule/dom-lte :transaction-rule/dom-gte :transaction-rule/yodlee-merchant]} include-coded? count]
|
||||
(->>
|
||||
(d/query
|
||||
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
||||
:transaction/bank-account [:bank-account/name]}
|
||||
:transaction/bank-account [:bank-account/name]
|
||||
:transaction/payment [:db/id]}
|
||||
])]
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
@@ -167,7 +168,7 @@
|
||||
(merge-query {:query {:where ['[?e :transaction/id]]}})))
|
||||
|
||||
(transduce (comp
|
||||
(take 15)
|
||||
(take (or count 15))
|
||||
(map first)
|
||||
(map #(dissoc % :transaction/id))
|
||||
(map (fn [x]
|
||||
@@ -185,9 +186,9 @@
|
||||
:dom-lte dom_lte
|
||||
:dom-gte dom_gte
|
||||
:yodlee-merchant (when yodlee_merchant_id {:db/id yodlee_merchant_id})}
|
||||
true))
|
||||
true 15))
|
||||
|
||||
|
||||
(defn run-transaction-rule [{:keys [id]} {:keys [transaction_rule_id]} value]
|
||||
(defn run-transaction-rule [{:keys [id]} {:keys [transaction_rule_id count]} value]
|
||||
(assert-admin id)
|
||||
(-test-transaction-rule id (tr/get-by-id transaction_rule_id) false))
|
||||
(-test-transaction-rule id (tr/get-by-id transaction_rule_id) false count))
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[auto-ap.graphql.transaction-rules :as g-tr]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri remove-nils]]
|
||||
[com.walmartlabs.lacinia :refer [execute]]
|
||||
@@ -122,8 +123,17 @@
|
||||
approval-status->graphql
|
||||
->graphql))
|
||||
|
||||
(defn match-transaction-rules [context {:keys [transaction_ids transaction_rule_id]} value]
|
||||
(defn match-transaction-rules [context {:keys [transaction_ids transaction_rule_id all]} value]
|
||||
(let [_ (assert-admin (:id context))
|
||||
transaction_ids (if all
|
||||
(->> (g-tr/run-transaction-rule context {:transaction_rule_id transaction_rule_id
|
||||
:count Integer/MAX_VALUE} nil)
|
||||
|
||||
(filter #(not (:transaction/payment %)))
|
||||
(map :id ))
|
||||
|
||||
|
||||
transaction_ids)
|
||||
transactions (transduce
|
||||
(comp
|
||||
(map d-transactions/get-by-id)
|
||||
@@ -134,7 +144,9 @@
|
||||
transaction-rule (update (tr/get-by-id transaction_rule_id) :transaction-rule/description #(some-> % re-pattern))]
|
||||
(doseq [transaction transactions]
|
||||
(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 transaction})))
|
||||
|
||||
(when (:transaction/payment transaction)
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
|
||||
|
||||
(defn assert-admin [id]
|
||||
(println "role" id)
|
||||
(when-not (= "admin" (:user/role id))
|
||||
(throw-unauthorized)))
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
(.get java.time.temporal.ChronoField/DAY_OF_MONTH))]
|
||||
(and
|
||||
(if description
|
||||
(re-find description (:transaction/description-original transaction))
|
||||
(re-find description (or (:transaction/description-original transaction) ""))
|
||||
true)
|
||||
(if dom-gte
|
||||
(>= transaction-dom dom-gte)
|
||||
|
||||
Reference in New Issue
Block a user