Makes it so vendors and invoices respect allowances.

This commit is contained in:
2023-02-03 20:59:52 -08:00
parent 1ecd076ba1
commit afa6b79fcc
7 changed files with 82 additions and 33 deletions

View File

@@ -183,7 +183,8 @@
(d/db conn))
(map (fn [i]
{:db/id i
:account/vendor-allowance :allowance/allowed})))
:account/vendor-allowance :allowance/allowed
:account/default-allowance :allowance/allowed})))
])
@@ -568,15 +569,19 @@
:requires [:auto-ap/add-account-options]}
:auto-ap/add-vendor-account-options {:txes [[{:db/ident :account/vendor-allowance
:auto-ap/add-vendor-account-options2 {:txes [[{:db/ident :account/vendor-allowance
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "Whether this account can be used for vendors"}
{:db/ident :account/default-allowance
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "Whether this account can be used generally"}
]]
:requires [:auto-ap/backfill-account-options]}
:auto-ap/backfill-account-options2 {:txes-fn `backfill-account-options2
:auto-ap/backfill-account-options3 {:txes-fn `backfill-account-options2
:requires [:auto-ap/add-vendor-account-options]}}
:requires [:auto-ap/add-vendor-account-options2]}}

View File

@@ -104,7 +104,8 @@
:account_search_result
{:fields {:name {:type 'String}
:id {:type :id}
:location {:type 'String}}}
:location {:type 'String}
:warning {:type 'String}}}
:yodlee_provider_account
{:fields {:id {:type 'Int}
@@ -361,6 +362,7 @@
:resolve :search-vendor}
:search_account {:type '(list :account_search_result)
:args {:query {:type 'String}
:allowance {:type :account_allowance}
:client_id {:type :id}}
:resolve :search-account}
@@ -518,6 +520,9 @@
{:enum-value :square}
{:enum-value :uber_eats}
{:enum-value :grubhub}]}
:account_allowance {:values [{:enum-value :vendor}
{:enum-value :invoice}]}
:integration_state {:values [{:enum-value :failed}
{:enum-value :success}
{:enum-value :unauthorized}]}

View File

@@ -74,50 +74,74 @@
(->graphql
(d-accounts/get-by-id (or id (get-in result [:tempids "new-account"])))))))
(defn search [context {query :query client :client_id} _]
(defn search [context {query :query client :client_id allowance :allowance} _]
(when client
(assert-can-see-client (:id context) client))
(let [query (cleanse-query query)
num (some-> (re-find #"([0-9]+)" query)
second
(not-empty )
Integer/parseInt)]
Integer/parseInt)
pattern [:db/id :account/numeric-code :account/location {:account/vendor-allowance [:db/ident]} {:account/invoice-allowance [:db/ident]}]
allowance (cond (= allowance :vendor)
:account/vendor-allowance
(= allowance :invoice)
:account/invoice-allowance
:else
:account/default-allowance)]
(if query
(if num
(->> (d/q '[:find ?n (pull ?i [:db/id :account/numeric-code :account/location])
:in $ ?numeric-code
(->> (d/q '[:find ?n (pull ?i pattern)
:in $ ?numeric-code ?allowance pattern
:where [?i :account/numeric-code ?numeric-code]
[?i :account/name ?n]]
[?i :account/name ?n]
(or [?i ?allowance :allowance/allowed]
[?i ?allowance :allowance/warn])]
(d/db conn)
num)
num
allowance
pattern)
(map (fn [[n a]]
{:name (str (:account/numeric-code a) " - " n)
:id (:db/id a)
:location (:account/location a)})))
:location (:account/location a)
:warning (when (= :allowance/warn (-> a allowance :db/ident))
"This account is not typically used for this purpose.")})))
(->> (d/q '[:find ?n (pull ?i [:db/id :account/numeric-code :account/location]) ?s
:in $ ?q
(->> (d/q '[:find ?n (pull ?i pattern) ?s
:in $ ?q ?allowance pattern
:where [(fulltext $ :account/search-terms ?q) [[?i ?n _ ?s]]]
[?i :account/numeric-code ?numeric-code]
(or [?i ?allowance :allowance/allowed]
[?i ?allowance :allowance/warn])
(or [?i :account/applicability :account-applicability/global]
[?i :account/applicability :account-applicability/optional])]
(d/db conn)
query)
query
allowance
pattern)
(concat (when client
(d/q '[:find ?n (pull ?a [:db/id :account/numeric-code :account/location]) ?s
:in $ ?c ?q
(d/q '[:find ?n (pull ?a pattern) ?s
:in $ ?c ?q ?allowance pattern
:where
[?i :account-client-override/client ?c]
[(fulltext $ :account-client-override/search-terms ?q) [[?i ?n _ ?s]]]
[?a :account/client-overrides ?i]
[?a :account/numeric-code ?numeric-code]]
[?a :account/numeric-code ?numeric-code]
(or [?a ?allowance :allowance/allowed]
[?a ?allowance :allowance/warn])]
(d/db conn)
client
query)))
query
allowance
pattern)))
(sort-by (comp - last))
(map (fn [[n a]]
{:name (str (:account/numeric-code a) " - " n)
:id (:db/id a)
:location (:account/location a)}))))
:location (:account/location a)
:warning (when (= :allowance/warn (-> a allowance :db/ident))
"This account is not typically used for this purpose.")}))))
[])))