From 523afd9d377d6728b6628dc0ce25e646a22fb375 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 28 Apr 2022 21:18:24 -0700 Subject: [PATCH] Started loading koala-production data, approve email invoices --- src/clj/auto_ap/background/mail.clj | 3 ++- src/clj/auto_ap/routes/invoices.clj | 4 ++-- src/clj/auto_ap/square/core.clj | 37 +++++++++++++++++------------ 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/clj/auto_ap/background/mail.clj b/src/clj/auto_ap/background/mail.clj index 8d803a2c..4648af56 100644 --- a/src/clj/auto_ap/background/mail.clj +++ b/src/clj/auto_ap/background/mail.clj @@ -67,7 +67,8 @@ (map #(assoc % :source-url (str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/" - s3-location))))] + s3-location) + :import-status :import-status/approved)))] (log/info "Found imports" imports) (invoices/import-uploaded-invoice {:user/role "admin"} imports )) (catch Exception e diff --git a/src/clj/auto_ap/routes/invoices.clj b/src/clj/auto_ap/routes/invoices.clj index 158b7596..01c650be 100644 --- a/src/clj/auto_ap/routes/invoices.clj +++ b/src/clj/auto_ap/routes/invoices.clj @@ -126,7 +126,7 @@ (throw (ex-info (str "No vendor with the name " vendor-code " was found.") {:vendor-code vendor-code}))))) -(defn import->invoice [{:keys [invoice-number source-url customer-identifier account-number total date vendor-code text full-text client-override vendor-override location-override]} clients] +(defn import->invoice [{:keys [invoice-number source-url customer-identifier account-number total date vendor-code text full-text client-override vendor-override location-override import-status]} clients] (let [[matching-client similarity] (cond account-number (parse/best-match clients account-number 0.0) customer-identifier (parse/best-match clients customer-identifier) @@ -147,7 +147,7 @@ :invoice/total (Double/parseDouble total) :invoice/date (to-date date) :invoice/location matching-location - :invoice/import-status :import-status/pending + :invoice/import-status (or import-status :import-status/pending) :invoice/outstanding-balance (Double/parseDouble total) :invoice/status :invoice-status/unpaid}))) diff --git a/src/clj/auto_ap/square/core.clj b/src/clj/auto_ap/square/core.clj index a6080485..92f4a170 100644 --- a/src/clj/auto_ap/square/core.clj +++ b/src/clj/auto_ap/square/core.clj @@ -192,21 +192,28 @@ ([client location] (daily-results client location nil)) ([client location d] - (->> (search client location d) - (filter (fn [order] - ;; sometimes orders stay open in square. At least one payment - ;; is needed to import, in order to avoid importing orders in-progress. - (and (or (> (count (:tenders order)) 0) - (seq (:returns order))) - (not= #{"FAILED"} - (set (map #(:status (:card_details %)) (:tenders order))))))) - (filter (fn [order] - (and - (not= "Koala" (:name (:source order))) - (not= "koala-production" (:name (:source order)))))) - (map #(order->sales-order client location %))))) - -#_(daily-results) + (let [search-results (search client location d) + koala-production-ids (->> search-results + (filter #(= "koala-production" (:name (:source %)))) + (map :id) + (into #{}))] + (->> search-results + (filter (fn [order] + ;; sometimes orders stay open in square. At least one payment + ;; is needed to import, in order to avoid importing orders in-progress. + (and (or (> (count (:tenders order)) 0) + (seq (:returns order))) + (not= #{"FAILED"} + (set (map #(:status (:card_details %)) (:tenders order))))))) + (filter (fn [order] + (not= "Koala" (:name (:source order))))) + (filter (fn has-linked-koala-production? [order] + ;; if a POS order is linked (via note) to a koala-production order, we want + ;; to keep the koala-production order, because it has taxes correct + (not (->> (:line_items order) + (map :note) + (every? koala-production-ids))))) + (map #(order->sales-order client location %)))))) (defn retry