make import more forgiving.
This commit is contained in:
@@ -76,8 +76,6 @@
|
|||||||
journal-entry (transaction->journal-entry (:db-after with-transaction)
|
journal-entry (transaction->journal-entry (:db-after with-transaction)
|
||||||
transaction-id
|
transaction-id
|
||||||
(:db/id transaction))]
|
(:db/id transaction))]
|
||||||
(println "TRANSACTION" transaction "JOURNAL" journal-entry "tempid " transaction-id)
|
|
||||||
|
|
||||||
(into [[:upsert-entity transaction]]
|
(into [[:upsert-entity transaction]]
|
||||||
(if journal-entry
|
(if journal-entry
|
||||||
[[:upsert-ledger journal-entry]]
|
[[:upsert-ledger journal-entry]]
|
||||||
@@ -86,6 +84,8 @@
|
|||||||
|
|
||||||
#_(comment
|
#_(comment
|
||||||
|
|
||||||
|
;; If transactions are failing, it is likely that there are multiple bank accounts linked
|
||||||
|
;; to yodlee or plaid. here is how i debugged
|
||||||
(upsert-transaction (dc/db auto-ap.datomic/conn) {:transaction/matched-rule 17592233159891,
|
(upsert-transaction (dc/db auto-ap.datomic/conn) {:transaction/matched-rule 17592233159891,
|
||||||
:db/id "34411061-4656-4e77-8cc0-2f2769b4324c",
|
:db/id "34411061-4656-4e77-8cc0-2f2769b4324c",
|
||||||
:transaction/status "POSTED",
|
:transaction/status "POSTED",
|
||||||
@@ -109,4 +109,45 @@
|
|||||||
["upsert-transaction"]
|
["upsert-transaction"]
|
||||||
(user/init-repl)
|
(user/init-repl)
|
||||||
|
|
||||||
|
(def my-transaction {:transaction/bank-account 17592232681223,
|
||||||
|
:transaction/date #inst "2024-02-24T08:00:00.000-00:00",
|
||||||
|
:transaction/matched-rule 17592233159891,
|
||||||
|
:transaction/client 17592232577980,
|
||||||
|
:transaction/status "POSTED",
|
||||||
|
:transaction/plaid-merchant
|
||||||
|
{:plaid-merchant/name "Rotten Robbie", :db/id "b2776792-9e2b-46e8-a9c8-bf80abea359e"},
|
||||||
|
:db/id "ac2efd80-bb03-48b2-b0d0-6b47a5c119dc",
|
||||||
|
:transaction/id "11a4a13e713d63f476009027e9a53e217e13d0192a37df8ab96c0eed4bdbe996",
|
||||||
|
:transaction/description-original "Rotten Robbie #03",
|
||||||
|
:transaction/approval-status {:db/id 17592231963877, :db/ident :transaction-approval-status/approved}, :transaction/amount -84.43,
|
||||||
|
:transaction/accounts [{:db/id "c402c7b3-c11b-484b-b670-bd48f79a3e5f", :transaction-account/account 17592231963549, :transaction-account/amount 84.43, :transaction-account/location "CB"}],
|
||||||
|
:transaction/raw-id "gQypbv5946F08op74wZmidDg8qD8Q1fM6gEBP",
|
||||||
|
:transaction/vendor 17592232627053})
|
||||||
|
|
||||||
|
(def my-journal {:journal-entry/alternate-description "Rotten Robbie #03",
|
||||||
|
:journal-entry/date #inst "2024-02-24T08:00:00.000-00:00",
|
||||||
|
:journal-entry/original-entity "ac2efd80-bb03-48b2-b0d0-6b47a5c119dc",
|
||||||
|
:journal-entry/client 17592232577980,
|
||||||
|
:journal-entry/line-items [{:journal-entry-line/credit 84.43, :journal-entry-line/account 17592232681223, :db/id "ac2efd80-bb03-48b2-b0d0-6b47a5c119dc-0", :journal-entry-line/location "A"}
|
||||||
|
{:journal-entry-line/account 17592231963549, :db/id "ac2efd80-bb03-48b2-b0d0-6b47a5c119dc-1", :journal-entry-line/debit 84.43, :journal-entry-line/location "CB"}
|
||||||
|
{:journal-entry-line/account 17592231963549, :db/id "ac2efd80-bb03-48b2-b0d0-6b47a5c119dc-2", :journal-entry-line/debit 84.43, :journal-entry-line/location "CB"}],
|
||||||
|
:journal-entry/source "transaction",
|
||||||
|
:journal-entry/cleared true,
|
||||||
|
:journal-entry/amount 84.43,
|
||||||
|
:journal-entry/vendor 17592232627053})
|
||||||
|
(dc/pull (dc/db auto-ap.datomic/conn) '[*] [:transaction/id "11a4a13e713d63f476009027e9a53e217e13d0192a37df8ab96c0eed4bdbe996"])
|
||||||
|
wl
|
||||||
|
(user/init-repl)
|
||||||
|
|
||||||
|
(or (when-let [original-entity (:journal-entry/original-entity my-journal)]
|
||||||
|
(dc/pull (dc/db auto-ap.datomic/conn) iol-ion.tx.upsert-ledger/extant-read [:journal-entry/original-entity original-entity]))
|
||||||
|
(when-let [external-id (:journal-entry/external-id my-journal)]
|
||||||
|
(dc/pull (dc/db auto-ap.datomic/conn) iol-ion.tx.upsert-ledger/extant-read [:journal-entry/external-id external-id])))
|
||||||
|
|
||||||
|
@(dc/transact auto-ap.datomic/conn [[:upsert-entity my-transaction]
|
||||||
|
[:upsert-ledger my-journal]])
|
||||||
|
|
||||||
|
(auto-ap.datomic/pull-attr (dc/db auto-ap.datomic/conn) :bank-account/code 17592232681223)
|
||||||
|
(auto-ap.datomic/pull-attr (dc/db auto-ap.datomic/conn) :bank-account/code 17592232681228)
|
||||||
|
|
||||||
)
|
)
|
||||||
File diff suppressed because one or more lines are too long
@@ -339,14 +339,20 @@
|
|||||||
:error :import-batch/error
|
:error :import-batch/error
|
||||||
:not-ready :import-batch/not-ready) inc))
|
:not-ready :import-batch/not-ready) inc))
|
||||||
(when (= :import action)
|
(when (= :import action)
|
||||||
(alog/info ::upserting-transaction :transaction [:upsert-transaction (transaction->txs transaction bank-account rule-applying-function)])
|
(try
|
||||||
(let [result (audit-transact [[:upsert-transaction (transaction->txs transaction bank-account rule-applying-function)]
|
(let [result (audit-transact [[:upsert-transaction (transaction->txs transaction bank-account rule-applying-function)]
|
||||||
{:db/id import-id
|
{:db/id import-id
|
||||||
:import-batch/entry (:db/id transaction)}]
|
:import-batch/entry (:db/id transaction)}]
|
||||||
{:user/name user
|
{:user/name user
|
||||||
:user/role ":admin"})]
|
:user/role ":admin"})]
|
||||||
(doseq [[_ n] (:tempids result)]
|
(doseq [[_ n] (:tempids result)]
|
||||||
(solr/touch-with-ledger n))))))
|
(solr/touch-with-ledger n)))
|
||||||
|
(catch Exception e
|
||||||
|
(swap! stats
|
||||||
|
#(update % :import-batch/error inc))
|
||||||
|
(alog/error ::invalid-transaction
|
||||||
|
:hint "It may be that the same bank account is linked twice"
|
||||||
|
:error e))))))
|
||||||
|
|
||||||
(get-stats [_]
|
(get-stats [_]
|
||||||
@stats)
|
@stats)
|
||||||
|
|||||||
Reference in New Issue
Block a user