 
 (defn- before-item-validation
   [item]
-  (cond-> item
-    true (update-in [:value] #(or % (:amount item)))
-    true (assoc :balance (bigdec 0))
-    true (update-in [:index] (fnil identity (Integer/MAX_VALUE)))
-    (string? (:account-id item)) (update-in [:account-id] #(Integer. %))
-    (nil? (:id item)) (dissoc :id)
+  (cond->
+    (-> item
+        (update-in [:value] #(or % (:amount item)))
+        (assoc :balance (bigdec 0))
+        (update-in [:index] (fnil identity (Integer/MAX_VALUE))))
+
+    (string? (:account-id item))
+    (update-in [:account-id] #(Integer. %))
+
+    (or (nil? (:id item))
+        (and
+          (string? (:id item))
+          (empty? (:id item))))
+    (dissoc :id)
+
     (and
       (string? (:id item))
-      (empty? (:id item))) (dissoc :id)
-    (and
-      (string? (:id item))
-      (not (empty? (:id item)))) (update-in [:id] #(UUID/fromString %))))
+      (not (empty? (:id item))))
+    (update-in [:id] #(UUID/fromString %)))) ; TODO: use coercion rule for this
 
 (def ^:private coercion-rules
   [(coercion/rule :uuid [:id])

(defn- create-transaction-and-adjust-balances
  [storage transaction]
  (let [created (link-lots storage (create-transaction* storage transaction))]
    (->> (:items transaction)

         ; create database records
         (map #(assoc % :transaction-id (:id created)))
         (map #(create-transaction-item* storage %))

         ; process indexes and balances, update affected accounts
         (group-by :account-id)
         (map second)
         (map #(sort-by :index %))
         (map first)
         (map #(get-previous-item storage %))
         (map #(recalculate-account-items storage %))
         (mapv #(recalculate-account-items storage %)))
    (reload storage created)))

(defn create

  ([item] (after-item-read item nil))
  ([item account]
   (if (map? item)
     (let [updated (-> item
                       (update-in [:action] keyword)
                       (assoc :reconciled? (= "completed" (:reconciliation-status item))))]
       (if account
         (polarize-item-amount updated account)
         updated))
     item)))

(defn- item-value-sum
