Vendor autopay re-instated.

This commit is contained in:
Bryce Covert
2020-11-16 19:28:04 -08:00
parent be1d5997b9
commit e53ee46b3c
4 changed files with 23 additions and 2 deletions

View File

@@ -62,6 +62,13 @@
(defn add-invoice-transaction [{:keys [total invoice_number location scheduled_payment client_id vendor_id vendor_name date due expense_accounts] :as in}]
(let [vendor (d-vendors/get-by-id vendor_id)
account (:vendor/default-account vendor)
due (or (and (:vendor/terms vendor)
(coerce/to-date
(time/plus date (time/days (d-vendors/terms-for-client-id vendor client_id)))))
due)
scheduled_payment (or scheduled_payment
(and (d-vendors/automatically-paid-for-client-id? vendor client_id)
due))
_ (when-not (:db/id account)
(throw (ex-info (str "Vendor '" (:vendor/name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id} )))]
(cond->
@@ -76,8 +83,6 @@
:invoice/date (coerce/to-date date)
:invoice/expense-accounts (map expense-account->entity
expense_accounts)}
(:vendor/terms vendor) (assoc :invoice/due (coerce/to-date
(time/plus date (time/days (d-vendors/terms-for-client-id vendor client_id)))))
due (assoc :invoice/due (coerce/to-date due))
scheduled_payment (assoc :invoice/scheduled-payment (coerce/to-date scheduled_payment)))))