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/doc "Data function that increments value of attribute a by amount."
|
||||||
:db/fn (d/function '{:lang "clojure"
|
:db/fn (d/function '{:lang "clojure"
|
||||||
:params [db e amount]
|
:params [db e amount]
|
||||||
:code (let [current-outstanding-balance (-> (d/entity db e) :invoice/outstanding-balance)
|
:code (let [invoice (-> (d/entity db e))
|
||||||
new-outstanding-balance (- current-outstanding-balance amount)]
|
current-outstanding-balance (-> invoice :invoice/outstanding-balance)
|
||||||
[[:db/add e :invoice/outstanding-balance new-outstanding-balance]
|
new-outstanding-balance (- current-outstanding-balance amount)]
|
||||||
[:db/add e :invoice/status (if (< -0.001 new-outstanding-balance 0.001)
|
(when (= (:invoice/status invoice)
|
||||||
:invoice-status/paid
|
:invoice-status/paid)
|
||||||
:invoice-status/unpaid)]])})}]] )
|
(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
|
(def add-client-identifier
|
||||||
[[{:db/ident :invoice/client-identifier
|
[[{:db/ident :invoice/client-identifier
|
||||||
@@ -165,7 +171,7 @@
|
|||||||
norms-map (merge {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema}
|
norms-map (merge {:auto-ap/base-schema {:txes auto-ap.datomic/base-schema}
|
||||||
:auto-ap/functions {:txes-fn 'auto-ap.datomic.migrate/functions
|
:auto-ap/functions {:txes-fn 'auto-ap.datomic.migrate/functions
|
||||||
:requires [:auto-ap/base-schema]}
|
: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]}
|
:requires [:auto-ap/functions]}
|
||||||
:auto-ap/migrate-vendors {:txes-fn 'auto-ap.datomic/migrate-vendors
|
:auto-ap/migrate-vendors {:txes-fn 'auto-ap.datomic/migrate-vendors
|
||||||
:requires [:auto-ap/base-schema]}
|
:requires [:auto-ap/base-schema]}
|
||||||
|
|||||||
Reference in New Issue
Block a user