reverts behavior if the totals don't match.
This commit is contained in:
@@ -67,6 +67,11 @@
|
||||
io/reader
|
||||
csv/read-csv))
|
||||
|
||||
(defn check-okay-amount? [i]
|
||||
(dollars=
|
||||
(:invoice/total i)
|
||||
(reduce + 0.0 (map :invoice-expense-account/amount (:invoice/expense-accounts i)))))
|
||||
|
||||
(defn code-individual-items [invoice csv-rows tax]
|
||||
(let [items (->> csv-rows
|
||||
butlast
|
||||
@@ -81,14 +86,18 @@
|
||||
)
|
||||
items-with-tax (update items (get-line-account "TAX")
|
||||
(fnil + 0.0)
|
||||
tax)]
|
||||
|
||||
(assoc invoice :invoice/expense-accounts
|
||||
tax)
|
||||
updated-invoice (assoc invoice :invoice/expense-accounts
|
||||
(for [[account amount] items-with-tax]
|
||||
#:invoice-expense-account {:db/id (random-tempid)
|
||||
:account account
|
||||
:location (:invoice/location invoice)
|
||||
:amount amount}))))
|
||||
:amount amount}))]
|
||||
(if (check-okay-amount? updated-invoice)
|
||||
updated-invoice
|
||||
(do (alog/warn ::itemized-expenses-not-adding-up
|
||||
:invoice updated-invoice)
|
||||
invoice))))
|
||||
|
||||
(defn extract-invoice-details [csv-rows sysco-vendor]
|
||||
(let [[header-row & csv-rows] csv-rows
|
||||
@@ -177,20 +186,17 @@
|
||||
|
||||
|
||||
|
||||
(defn check-okay-amount? [i]
|
||||
(dollars=
|
||||
(:invoice/total i)
|
||||
(reduce + 0.0 (map :invoice-expense-account/amount (:invoice/expense-accounts i)))))
|
||||
|
||||
|
||||
(comment
|
||||
(with-bindings { #'bucket-name "data.prod.app.integreatconsult.com"}
|
||||
(doall
|
||||
(for [n (range 800 940 )
|
||||
(for [n (range 930 940 )
|
||||
:let [result (-> (get-test-invoice-file n)
|
||||
read-sysco-csv
|
||||
(extract-invoice-details (get-sysco-vendor))
|
||||
)]
|
||||
:when (not (check-okay-amount? result))]
|
||||
#_#_:when (not (check-okay-amount? result))]
|
||||
|
||||
result)))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user