Fix Datomic conflict when spreading shared location across accounts

When a transaction account had 'Shared' location, spread-account was
creating multiple accounts with the same :db/id but different locations,
causing a datoms-conflict error in Datomic.

Now generates unique tempids for all spread accounts beyond the first,
preventing entity ID collisions while preserving the original account's
tempid for the first location.

Fixes: Two datoms in the same transaction conflict on :transaction-account/location
This commit is contained in:
2026-05-20 21:33:44 -07:00
parent dd4d1a6d4f
commit 8189a7648b

View File

@@ -1002,6 +1002,9 @@
(let [{:keys [base-amount remainder]} (calculate-spread (:transaction-account/amount account) (count locations))] (let [{:keys [base-amount remainder]} (calculate-spread (:transaction-account/amount account) (count locations))]
(map-indexed (fn [idx _] (map-indexed (fn [idx _]
(assoc account (assoc account
:db/id (if (= idx 0)
(:db/id account)
(random-tempid))
:transaction-account/amount (+ base-amount (if (< idx remainder) 1 0)) :transaction-account/amount (+ base-amount (if (< idx remainder) 1 0))
:transaction-account/location (nth locations idx))) :transaction-account/location (nth locations idx)))
locations)) locations))