making tests pass again
This commit is contained in:
@@ -40,7 +40,12 @@
|
||||
|
||||
(def integreat-schema
|
||||
{
|
||||
:scalars {:id {:parse #(when % (Long/parseLong %))
|
||||
:scalars {:id {:parse #(cond (number? %)
|
||||
%
|
||||
|
||||
%
|
||||
(Long/parseLong %))
|
||||
|
||||
:serialize #(.toString %)}
|
||||
:ident {:parse (fn [x] {:db/ident x})
|
||||
:serialize #(or (:ident %) (:db/ident %) %)}
|
||||
|
||||
@@ -196,46 +196,57 @@
|
||||
:else
|
||||
:import)))
|
||||
|
||||
(defn maybe-assoc-check-number [transaction]
|
||||
(if-let [check-number (or (:transaction/check-number transaction)
|
||||
(extract-check-number transaction))]
|
||||
(assoc transaction :transaction/check-number transaction)
|
||||
transaction))
|
||||
|
||||
|
||||
(defn maybe-clear-payment [{:transaction/keys [check-number client bank-account amount id] :as transaction}]
|
||||
(when-let [existing-payment (transaction->existing-payment transaction check-number client bank-account amount id)]
|
||||
(assoc transaction
|
||||
:transaction/approval-status :transaction-approval-status/approved
|
||||
:transaction/payment {:db/id (:db/id existing-payment)
|
||||
:payment/status :payment-status/cleared}
|
||||
:transaction/vendor (:db/id (:payment/vendor existing-payment))
|
||||
:transaction/location "A"
|
||||
:transaction/accounts [#:transaction-account
|
||||
{:account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"]))
|
||||
:location "A"
|
||||
:amount (Math/abs (double amount))}])))
|
||||
|
||||
(defn maybe-autopay-invoices [{:transaction/keys [amount client bank-account] :as transaction}]
|
||||
(when-let [autopay-invoices-matches (seq (match-transaction-to-unfulfilled-autopayments amount client))]
|
||||
(add-new-payment autopay-invoices-matches bank-account client)))
|
||||
|
||||
(defn maybe-clear-expected-deposit [{:transaction/keys [amount client date] :as transaction}]
|
||||
(when (>= amount 0.0)
|
||||
(when-let [expected-deposit (find-expected-deposit client amount (coerce/to-date-time date))]
|
||||
(assoc transaction :transaction/expected-deposit {:db/id expected-deposit
|
||||
:expected-deposit/status :expected-deposit-status/cleared}))))
|
||||
|
||||
(defn maybe-code [{:transaction/keys [client amount] :as transaction} apply-rules valid-locations]
|
||||
(if-let [unpaid-invoices (seq (match-transaction-to-unpaid-invoices amount client))]
|
||||
nil
|
||||
(apply-rules transaction valid-locations)))
|
||||
|
||||
(defn transaction->txs [transaction bank-account apply-rules]
|
||||
(let [bank-account-id (:db/id bank-account)
|
||||
client (:client/_bank-accounts bank-account)
|
||||
client-id (:db/id client)
|
||||
valid-locations (or (:bank-account/locations bank-account) (:client/locations client))]
|
||||
(into []
|
||||
(let [{:transaction/keys [amount id date]} transaction
|
||||
check-number (extract-check-number transaction)
|
||||
existing-check (transaction->existing-payment transaction check-number client-id bank-account-id amount id)
|
||||
autopay-invoices-matches (when-not existing-check
|
||||
(match-transaction-to-unfulfilled-autopayments amount client-id))
|
||||
unpaid-invoices-matches (when-not existing-check
|
||||
(match-transaction-to-unpaid-invoices amount client-id ))
|
||||
expected-deposit (when (and (> amount 0.0)
|
||||
(not existing-check))
|
||||
(find-expected-deposit (:db/id client) amount (coerce/to-date-time date)))]
|
||||
(cond->
|
||||
[(assoc transaction :transaction/approval-status :transaction-approval-status/unapproved)]
|
||||
check-number (update 0 #(assoc % :transaction/check-number check-number))
|
||||
existing-check (update 0 #(assoc % :transaction/approval-status :transaction-approval-status/approved
|
||||
:transaction/payment {:db/id (:db/id existing-check)
|
||||
:payment/status :payment-status/cleared}
|
||||
:transaction/vendor (:db/id (:payment/vendor existing-check))
|
||||
:transaction/location "A"
|
||||
:transaction/accounts [#:transaction-account
|
||||
{:account (:db/id (a/get-account-by-numeric-code-and-sets 21000 ["default"]))
|
||||
:location "A"
|
||||
:amount (Math/abs (double amount))}]))
|
||||
|
||||
;; temporarily removed to automatically match autopaid invoices
|
||||
#_(and (not existing-check)
|
||||
(seq autopay-invoices-matches)) #_(add-new-payment autopay-invoices-matches bank-account-id client-id)
|
||||
expected-deposit (update 0 #(assoc % :transaction/expected-deposit {:db/id expected-deposit
|
||||
:expected-deposit/status :expected-deposit-status/cleared}))
|
||||
|
||||
|
||||
(and (not (seq autopay-invoices-matches))
|
||||
(not (seq unpaid-invoices-matches))
|
||||
(not expected-deposit)) (update 0 #(apply-rules % valid-locations))
|
||||
true (update 0 remove-nils))))))
|
||||
valid-locations (or (:bank-account/locations bank-account) (:client/locations client))
|
||||
code-fn (some-fn maybe-clear-payment
|
||||
maybe-clear-expected-deposit
|
||||
#_maybe-autopay-invoices
|
||||
#(maybe-code % apply-rules valid-locations)
|
||||
identity)]
|
||||
[(-> transaction
|
||||
(assoc :transaction/client client-id)
|
||||
(assoc :transaction/bank-account bank-account-id)
|
||||
(assoc :transaction/approval-status :transaction-approval-status/unapproved)
|
||||
maybe-assoc-check-number
|
||||
code-fn)]))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user