From 96ec3b1cf521ac2366d532bc8993f95737398257 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 31 Aug 2019 07:08:57 -0700 Subject: [PATCH] makes import check for accoutns --- src/clj/auto_ap/datomic/accounts.clj | 25 ++++++++++++++----------- src/clj/auto_ap/graphql/ledger.clj | 4 ++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/clj/auto_ap/datomic/accounts.clj b/src/clj/auto_ap/datomic/accounts.clj index 89cea5f9..c58fdb49 100644 --- a/src/clj/auto_ap/datomic/accounts.clj +++ b/src/clj/auto_ap/datomic/accounts.clj @@ -3,17 +3,20 @@ [auto-ap.graphql.utils :refer [->graphql]] [auto-ap.datomic :refer [uri merge-query]])) -(defn get-accounts [args] - (let [query (cond-> {:query {:find ['(pull ?e [* {:account/type [:db/ident :db/id]}])] - :in ['$] - :where [['?e :account/name]]} - :args [(d/db (d/connect uri))]} - (:account-set args) (merge-query {:query {:in ['?account-set] - :where [['?e :account/account-set '?account-set]]} - :args [(:account-set args)]}))] - (->> - (d/query query) - (map first)))) +(defn get-accounts + ([] + (get-accounts {})) + ([args] + (let [query (cond-> {:query {:find ['(pull ?e [* {:account/type [:db/ident :db/id]}])] + :in ['$] + :where [['?e :account/name]]} + :args [(d/db (d/connect uri))]} + (:account-set args) (merge-query {:query {:in ['?account-set] + :where [['?e :account/account-set '?account-set]]} + :args [(:account-set args)]}))] + (->> + (d/query query) + (map first))))) (defn get-account-by-numeric-code-and-sets [numeric-code sets] (let [query (cond-> {:query {:find ['(pull ?e [* {:account/type [:db/ident :db/id]}])] diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index 4ed26a13..2814089a 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -167,8 +167,8 @@ {} (:entries args)) all-vendors (into all-vendors new-hidden-vendors) + all-accounts (transduce (map :account/code) conj #{} (a/get-accounts)) transaction (doall (map - (assoc-error (fn [entry] (let [entry (-> entry (update :amount #(Double/parseDouble %)) @@ -207,7 +207,7 @@ (:location ea)) (throw (Exception. (str "Location '" (:location ea) "' not found.")))) - (when (and (not (re-matches #"^[0-9]+$" (:account_identifier ea))) + (when (and (not (all-accounts (:account_identifier ea))) (not (get (get all-client-bank-accounts (:client_code entry)) (:account_identifier ea))))