fixes new wine warehouse format.

This commit is contained in:
2024-06-07 10:52:04 -07:00
parent 3db0629895
commit 0cabe30999
4 changed files with 42 additions and 30 deletions

View File

@@ -575,10 +575,14 @@
]
))
(defn match-vendor [vendor-code forced-vendor]
(defn match-vendor [vendor-code forced-vendor vendor-search]
(when (and (not forced-vendor) (str/blank? vendor-code))
(throw (ex-info (str "No vendor found. Please supply an forced vendor.")
{:vendor-code vendor-code})))
(if vendor-search
(throw (ex-info (format "No vendor found. Searched for '%s'. Please supply an forced vendor."
vendor-search)
{:vendor-code vendor-code}))
(throw (ex-info (str "No vendor found. Please supply an forced vendor.")
{:vendor-code vendor-code}))))
(let [vendor-id (or forced-vendor
(->> (dc/q
{:find ['?vendor]
@@ -601,7 +605,11 @@
(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 import-status]}]
(defn import->invoice [{:keys [invoice-number source-url customer-identifier account-number total date vendor-code text full-text client-override vendor-search vendor-override location-override import-status]}]
(when-not total
(throw (Exception. "Couldn't parse total from file.")))
(when-not date
(throw (Exception. "Couldn't parse date from file.")))
(let [matching-client (cond
client-override client-override
account-number (:db/id (d-clients/exact-match account-number))
@@ -613,7 +621,8 @@
:matching (when matching-client
(dc/pull (dc/db conn) [:client/name :client/code] matching-client)))
matching-vendor (match-vendor vendor-code vendor-override)
matching-vendor (match-vendor vendor-code vendor-override vendor-search)
matching-location (or (when-not (str/blank? location-override)
location-override)
(parse/best-location-match (dc/pull (dc/db conn)