From e5a2d0bbbaa8e7de992d0eb0bc6a6beaa09ec2ea Mon Sep 17 00:00:00 2001 From: Bryce Date: Wed, 27 May 2026 13:22:29 -0700 Subject: [PATCH] Simplify sysco line item allocation: use actual amounts, default unmatched to food cost (50000) --- AGENTS.md | 5 +++++ src/clj/auto_ap/jobs/sysco.clj | 32 +++++++++++--------------------- 2 files changed, 16 insertions(+), 21 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index dd50a17e..4312c46f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -20,6 +20,11 @@ clj-nrepl-eval -p PORT "(+ 1 2 3)" # evaluate clojure code ``` +### Editing clojure + +When editing clojure, use the clojure-mcp editing tools, or ask @clojure-author to make the change. It is critical that you +do not use the file editing tools unless absolutely necessary. + Often times, if a file won't compile, first clj-paren-repair on the file, then try again. If it doesn't wor still, try cljfmt check. ### Running the Application diff --git a/src/clj/auto_ap/jobs/sysco.clj b/src/clj/auto_ap/jobs/sysco.clj index 6023d18c..e772e057 100644 --- a/src/clj/auto_ap/jobs/sysco.clj +++ b/src/clj/auto_ap/jobs/sysco.clj @@ -114,27 +114,17 @@ {} line-items) total-line-amount (reduce + 0.0 (vals expense-accounts)) - accounts (if (zero? total-line-amount) - [] - (vec (for [[account amount] expense-accounts] - (let [ratio (/ amount total-line-amount) - cents (int (Math/round (* ratio abs-total 100)))] - #:invoice-expense-account {:db/id (random-tempid) - :account account - :location (:invoice/location invoice) - :amount (* 0.01 cents)})))) - accounts (mapv - (fn [a] - (update a :invoice-expense-account/amount - #(with-precision 2 - (double (.setScale (bigdec %) 2 java.math.RoundingMode/HALF_UP))))) - accounts) - leftover (with-precision 2 (.round (bigdec (- abs-total - (reduce + 0.0 (map :invoice-expense-account/amount accounts)))) - *math-context*)) - accounts (if (seq accounts) - (update-in accounts [(dec (count accounts)) :invoice-expense-account/amount] #(+ % (double leftover))) - [])] + leftover (- abs-total total-line-amount) + food-cost-account (get-line-account nil) + adjusted-accounts (if (zero? leftover) + expense-accounts + (update expense-accounts food-cost-account (fnil + 0.0) leftover)) + accounts (vec (for [[account amount] adjusted-accounts] + #:invoice-expense-account {:db/id (random-tempid) + :account account + :location (:invoice/location invoice) + :amount (with-precision 2 + (double (.setScale (bigdec amount) 2 java.math.RoundingMode/HALF_UP)))}))] (dissoc (assoc invoice :invoice/expense-accounts accounts) :line-items)))) (defn maybe-code-line-items [invoice]