From d1a06f24f27142152b5fa63c767c3702976e57d4 Mon Sep 17 00:00:00 2001 From: Bryce Date: Thu, 2 May 2024 23:14:05 -0700 Subject: [PATCH] reverts behavior if the totals don't match. --- src/clj/auto_ap/jobs/sysco.clj | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/clj/auto_ap/jobs/sysco.clj b/src/clj/auto_ap/jobs/sysco.clj index bdce0c7a..82d1e101 100644 --- a/src/clj/auto_ap/jobs/sysco.clj +++ b/src/clj/auto_ap/jobs/sysco.clj @@ -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)))