huge number of changes to start making all usages of expense accounts dynamic.

This commit is contained in:
Bryce Covert
2019-04-12 15:39:32 -07:00
parent e64820d71a
commit b6e73f0bfb
21 changed files with 103 additions and 181 deletions

View File

@@ -4,6 +4,7 @@
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.invoices :as d-invoices]
[auto-ap.datomic.accounts :as d-accounts]
[auto-ap.expense-accounts :as expense-accounts]
[auto-ap.graphql.checks :as gq-checks]
[auto-ap.time :refer [parse iso-date]]
@@ -53,8 +54,8 @@
(defn add-invoice-transaction [{:keys [total invoice_number location client_id vendor_id vendor_name date] :as in}]
(let [vendor (d-vendors/get-by-id vendor_id)
expense-account-id (:vendor/default-expense-account vendor)
_ (when-not expense-account-id
account (:vendor/default-account vendor)
_ (when-not (:db/id account)
(throw (ex-info (str "Vendor '" (:vendor/name vendor) "' does not have a default expense acount.") {:vendor-id vendor_id} )))]
{:db/id "invoice"
:invoice/invoice-number invoice_number
@@ -65,8 +66,8 @@
:invoice/outstanding-balance total
:invoice/status :invoice-status/unpaid
:invoice/date (coerce/to-date date)
:invoice/expense-accounts [{:invoice-expense-account/expense-account-id expense-account-id
:invoice-expense-account/location (get-in expense-accounts/expense-accounts [expense-account-id :location] location)
:invoice/expense-accounts [{:invoice-expense-account/account (:db/id account)
:invoice-expense-account/location (:account/location account location)
:invoice-expense-account/amount total}]}))
(defn add-invoice [context {{:keys [total invoice_number location client_id vendor_id vendor_name date] :as in} :invoice} value]
@@ -188,12 +189,12 @@
deleted (set/difference existing-ids specified-ids)
updated (map
(fn [{:keys [id expense_account_id amount location]}]
(fn [{:keys [id account_id amount location]}]
{:db/id invoice-id
:invoice/expense-accounts [#:invoice-expense-account {
:amount (Double/parseDouble amount)
:db/id id
:expense-account-id expense_account_id
:account account_id
:location location}
]}
)

View File

@@ -8,14 +8,15 @@
[clojure.set :as set]))
(defn upsert-vendor [context {{:keys [id name code print_as primary_contact secondary_contact address default_expense_account invoice_reminder_schedule] :as in} :vendor} value]
(let [transaction [(remove-nils #:vendor {:db/id (if id
(defn upsert-vendor [context {{:keys [id name code print_as primary_contact secondary_contact address default_account_id invoice_reminder_schedule] :as in} :vendor} value]
(let [_ (println default_account_id)
transaction [(remove-nils #:vendor {:db/id (if id
id
"vendor")
:name name
:code code
:print-as print_as
:default-expense-account default_expense_account
:default-account default_account_id
:invoice-reminder-schedule (keyword invoice_reminder_schedule)
:address (when address
(remove-nils #:address {:db/id (if (:id address)