fixing minor bugs in general produce import

This commit is contained in:
2023-05-08 20:55:06 -07:00
parent aaa7c54f0c
commit 13b9bec09f
2 changed files with 41 additions and 36 deletions

View File

@@ -65,40 +65,43 @@
(defmethod extract-invoice-details :general-produce (defmethod extract-invoice-details :general-produce
[k input-stream clients] [k input-stream clients]
(log/info ::parsing-general-produce :key k) (log/info ::parsing-general-produce :key k)
(try (let [missing-client-hints (atom #{})]
(->> (read-csv input-stream) (try
(drop 1) (->> (read-csv input-stream)
(filter (fn [[_ _ _ _ _ _ _ _ _ _ _ break-flag]] (drop 1)
(= "Y" break-flag))) #_(filter (fn [[_ _ _ _ _ _ _ _ _ _ _ break-flag]]
(map (fn [[_ location-hint invoice-number ship-date invoice-total ]] (= "Y" break-flag)))
(let [matching-client (and location-hint (map (fn [[_ location-hint invoice-number ship-date invoice-total ]]
(parse/exact-match clients location-hint)) (let [matching-client (and location-hint
location (parse/best-location-match matching-client location-hint location-hint ) (parse/exact-match clients location-hint))
vendor (d/pull (d/db conn) '[:vendor/default-account] :vendor/general-produce)] location (parse/best-location-match matching-client location-hint location-hint )
(when-not matching-client vendor (d/pull (d/db conn) '[:vendor/default-account] :vendor/general-produce)]
(log/warn ::missing-client (when-not (and matching-client
:client-hint location-hint)) (not (@missing-client-hints location-hint)))
{:invoice/location location (log/warn ::missing-client
:invoice/date (coerce/to-date (atime/parse ship-date atime/normal-date)) :client-hint location-hint)
:invoice/invoice-number invoice-number (swap! missing-client-hints conj location-hint))
:invoice/total (Double/parseDouble invoice-total) {:invoice/location location
:invoice/vendor :vendor/general-produce :invoice/date (coerce/to-date (atime/parse ship-date atime/normal-date))
:invoice/outstanding-balance (Double/parseDouble invoice-total) :invoice/invoice-number invoice-number
:invoice/client (:db/id matching-client) :invoice/total (Double/parseDouble invoice-total)
:invoice/import-status :import-status/imported :invoice/vendor :vendor/general-produce
:invoice/status :invoice-status/unpaid :invoice/outstanding-balance (Double/parseDouble invoice-total)
:invoice/client-identifier location-hint :invoice/client (:db/id matching-client)
:invoice/expense-accounts [{:invoice-expense-account/account :invoice/import-status :import-status/imported
(-> vendor :vendor/default-account :db/id) :invoice/status :invoice-status/unpaid
:invoice-expense-account/location location :invoice/client-identifier location-hint
:invoice-expense-account/amount (Math/abs (Double/parseDouble invoice-total)) :invoice/expense-accounts [{:invoice-expense-account/account
}]}))) (-> vendor :vendor/default-account :db/id)
(filter :invoice/client) :invoice-expense-account/location location
(into [])) :invoice-expense-account/amount (Math/abs (Double/parseDouble invoice-total))
(catch Exception e }]})))
(log/error ::cant-import-general-produce (filter :invoice/client)
:error e) (into []))
[]))) (catch Exception e
(log/error ::cant-import-general-produce
:error e)
[]))))
(defmethod extract-invoice-details :unknown (defmethod extract-invoice-details :unknown
[k input-stream clients] [k input-stream clients]
@@ -245,6 +248,7 @@
(->> (extract-invoice-details k (->> (extract-invoice-details k
is is
clients) clients)
(set)
(map (fn [i] (map (fn [i]
(log/info ::importing-invoice (log/info ::importing-invoice
:invoice i) :invoice i)

View File

@@ -631,7 +631,7 @@
(defn cash-drawer-shifts (defn cash-drawer-shifts
([client l] ([client l]
(cash-drawer-shifts client l (time/plus (time/now) (time/days -14)) (time/now))) (cash-drawer-shifts client l (time/plus (time/now) (time/days -75)) (time/now)))
([client l start end] ([client l start end]
(de/chain (manifold-api-call {:url (str "https://connect.squareup.com/v2/cash-drawers/shifts" (de/chain (manifold-api-call {:url (str "https://connect.squareup.com/v2/cash-drawers/shifts"
"?" "?"
@@ -639,7 +639,8 @@
(url/map->query (url/map->query
{:location_id (:square-location/square-id l) {:location_id (:square-location/square-id l)
:begin_time (->square-date start) :begin_time (->square-date start)
:end_time (->square-date end)})) :end_time (->square-date end)
:limit 1000}))
:method :get :method :get
:headers (client-base-headers client "2023-04-19") :headers (client-base-headers client "2023-04-19")