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:
@@ -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))
|
||||||
|
|||||||
Reference in New Issue
Block a user