so many bug fixes.
This commit is contained in:
@@ -196,11 +196,17 @@
|
||||
_ (println client-id)
|
||||
headers (map read-string header)
|
||||
code->existing-account (by :account/numeric-code (map first (d/query {:query {:find ['(pull ?e [:account/numeric-code
|
||||
{:account/applicability [:db/ident]}
|
||||
:db/id])]
|
||||
:in ['$]
|
||||
:where ['[?e :account/name]]}
|
||||
:args [(d/db conn)]})))
|
||||
|
||||
existing-account-overrides (d/query (-> {:query {:find ['?e]
|
||||
:in ['$ '?client-id]
|
||||
:where [['?e :account-client-override/client '?client-id]]}
|
||||
:args [(d/db (d/connect uri)) client-id]}))
|
||||
|
||||
|
||||
|
||||
_ (if-let [bad-rows (seq (->> rows
|
||||
@@ -219,27 +225,46 @@
|
||||
txes (transduce
|
||||
(comp
|
||||
|
||||
(filter (fn [[account _ override-name]]
|
||||
(and
|
||||
(not (str/blank? override-name))
|
||||
(not (str/blank? account)))))
|
||||
(map (fn parse-map [[account account-name override-name _ type]]
|
||||
(let [code (Integer/parseInt account)
|
||||
existing-id (:db/id (code->existing-account code))]
|
||||
(cond-> {:account/client-overrides [{:account-client-override/client client-id
|
||||
:account-client-override/name override-name}]}
|
||||
existing-id (assoc :db/id existing-id)
|
||||
(not existing-id) (assoc :account/applicability :account-applicability/customized
|
||||
:account/name account-name
|
||||
:account/account-set "default"
|
||||
:account/numeric-code code
|
||||
:account/code (str code)
|
||||
:account/type (if (str/blank? type)
|
||||
:account-type/expense
|
||||
(keyword "account-type" (str/lower-case type)))))))))
|
||||
|
||||
(mapcat (fn parse-map [[account account-name override-name _ type]]
|
||||
(let [code (some-> account
|
||||
not-empty
|
||||
Integer/parseInt)
|
||||
existing (code->existing-account code)]
|
||||
(cond (not code)
|
||||
[]
|
||||
|
||||
(and existing (or (#{:account-applicability/optional :account-applicability/customized}
|
||||
(:db/ident (:account/applicability existing)))
|
||||
(and (not-empty override-name)
|
||||
(not-empty account-name)
|
||||
(not= override-name account-name)
|
||||
)))
|
||||
[{:db/id (:db/id existing)
|
||||
:account/client-overrides [{:account-client-override/client client-id
|
||||
:account-client-override/name (or (not-empty override-name)
|
||||
(not-empty account-name))}]}]
|
||||
|
||||
(not existing)
|
||||
[{:account/applicability :account-applicability/customized
|
||||
:account/name account-name
|
||||
:account/account-set "default"
|
||||
:account/numeric-code code
|
||||
:account/code (str code)
|
||||
:account/type (if (str/blank? type)
|
||||
:account-type/expense
|
||||
(keyword "account-type" (str/lower-case type)))
|
||||
:account/client-overrides [{:account-client-override/client client-id
|
||||
:account-client-override/name (or (not-empty override-name)
|
||||
(not-empty account-name))}]}]
|
||||
:else
|
||||
[])))))
|
||||
|
||||
conj
|
||||
[]
|
||||
(mapv
|
||||
(fn [[x]]
|
||||
[:db/retractEntity x])
|
||||
existing-account-overrides)
|
||||
rows)]
|
||||
|
||||
txes
|
||||
|
||||
Reference in New Issue
Block a user