Likely makes it impossible to double pay an invoice
This commit is contained in:
@@ -55,12 +55,18 @@
|
||||
:db/doc "Data function that increments value of attribute a by amount."
|
||||
:db/fn (d/function '{:lang "clojure"
|
||||
:params [db e amount]
|
||||
:code (let [current-outstanding-balance (-> (d/entity db e) :invoice/outstanding-balance)
|
||||
new-outstanding-balance (- current-outstanding-balance amount)]
|
||||
[[:db/add e :invoice/outstanding-balance new-outstanding-balance]
|
||||
[:db/add e :invoice/status (if (< -0.001 new-outstanding-balance 0.001)
|
||||
:invoice-status/paid
|
||||
:invoice-status/unpaid)]])})}]] )
|
||||
:code (let [invoice (-> (d/entity db e))
|
||||
current-outstanding-balance (-> invoice :invoice/outstanding-balance)
|
||||
new-outstanding-balance (- current-outstanding-balance amount)]
|
||||
(when (= (:invoice/status invoice)
|
||||
:invoice-status/paid)
|
||||
(throw (ex-info "This invoice has already been paid" {:validation-message "This invoice has already been paid."
|
||||
:status (:invoice/status invoice)
|
||||
:id (:db/id invoice)})))
|
||||
[[:db/add e :invoice/outstanding-balance new-outstanding-balance]
|
||||
[:db/add e :invoice/status (if (< -0.001 new-outstanding-balance 0.001)
|
||||
:invoice-status/paid
|
||||
:invoice-status/unpaid)]])})}]] )
|
||||
|
||||
(def add-client-identifier
|
||||
[[{:db/ident :invoice/client-identifier
|
||||
@@ -165,7 +171,7 @@
|
||||
norms-map (merge {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema}
|
||||
:auto-ap/functions {:txes-fn 'auto-ap.datomic.migrate/functions
|
||||
:requires [:auto-ap/base-schema]}
|
||||
:auto-ap/fx-pay-function-2 {:txes-fn 'auto-ap.datomic.migrate/fix-pay-function
|
||||
:auto-ap/fx-pay-function-10 {:txes-fn 'auto-ap.datomic.migrate/fix-pay-function
|
||||
:requires [:auto-ap/functions]}
|
||||
:auto-ap/migrate-vendors {:txes-fn 'auto-ap.datomic/migrate-vendors
|
||||
:requires [:auto-ap/base-schema]}
|
||||
|
||||
Reference in New Issue
Block a user