Resets the database, now using real locations for each vendor, and matching against those locations.
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
[honeysql.core :as sql]
|
||||
[honeysql.helpers :as helpers]))
|
||||
|
||||
(def all-keys #{:company-id :vendor-id :imported :potential-duplicate :total :invoice-number :date :outstanding-balance})
|
||||
(def all-keys #{:company-id :vendor-id :imported :potential-duplicate :total :invoice-number :date :outstanding-balance :default-location})
|
||||
|
||||
(defn insert-multi! [rows]
|
||||
(j/insert-multi! (get-conn)
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
|
||||
(defn upsert-multi! [rows]
|
||||
(let [k (vec (map #(keyword (kebab->snake (name %))) [:company-id :vendor-id :invoice-number :total :date :imported :status :outstanding-balance]))
|
||||
(let [k (vec (map #(keyword (kebab->snake (name %))) [:company-id :vendor-id :invoice-number :total :date :imported :status :outstanding-balance :default-location]))
|
||||
column-names (str/join "," (map name k))]
|
||||
(reduce
|
||||
(fn [affected rows]
|
||||
@@ -31,7 +31,7 @@
|
||||
(map clj->db )
|
||||
(map (apply juxt k))))]]
|
||||
:insert-into [[:invoices k]
|
||||
{:select [:v.company-id :v.vendor-id :v.invoice-number :v.total (sql/raw "cast(v.date as timestamp)") :v.imported :v.status :v.outstanding-balance]
|
||||
{:select [:v.company-id :v.vendor-id :v.invoice-number :v.total (sql/raw "cast(v.date as timestamp)") :v.imported :v.status :v.outstanding-balance :v.default-location]
|
||||
:from [:v]
|
||||
:left-join [[:invoices :exist]
|
||||
[:and
|
||||
|
||||
@@ -20,8 +20,8 @@
|
||||
|
||||
(defn assign-defaults! []
|
||||
(j/db-do-prepared (get-conn)
|
||||
(sql/format {:insert-into [[:invoices-expense-accounts [:invoice-id :expense-account-id :amount]]
|
||||
{:select [:i.id :v.default-expense-account :i.total]
|
||||
(sql/format {:insert-into [[:invoices-expense-accounts [:invoice-id :expense-account-id :amount :location]]
|
||||
{:select [:i.id :v.default-expense-account :i.total :i.default_location]
|
||||
:from [[:invoices :i]]
|
||||
:join [[:vendors :v]
|
||||
[:= :v.id :i.vendor-id]]
|
||||
|
||||
Reference in New Issue
Block a user