defaulting vendor.
This commit is contained in:
@@ -104,13 +104,22 @@
|
|||||||
:on-error [::forms/save-error ::edit-transaction]}})))
|
:on-error [::forms/save-error ::edit-transaction]}})))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::change-account
|
::change-vendor
|
||||||
(fn [{:keys [db]} [_ f a]]
|
[(forms/in-form ::edit-transaction)]
|
||||||
(if-let [forced-location (and (= f [:account-id])
|
(fn [{{:keys [data]} :db} [_ field value]]
|
||||||
(:location @(re-frame/subscribe [::subs/account a])))]
|
(let [has-only-one-expense-account? (and value
|
||||||
{:dispatch-n [[::forms/change ::edit-transaction f a]
|
(or (not (seq (:accounts data)))
|
||||||
[::forms/change ::edit-transaction [:location] forced-location]]}
|
(<= 1 (count (:accounts data))))
|
||||||
{:dispatch [::forms/change ::edit-transaction f a]})))
|
(not (get-in data [:accounts 0 :account :id])))]
|
||||||
|
(if has-only-one-expense-account?
|
||||||
|
{:dispatch [::forms/change ::edit-transaction
|
||||||
|
field value
|
||||||
|
[:accounts] [{:id (str "new-" (random-uuid))
|
||||||
|
:amount (Math/abs (:amount data))
|
||||||
|
:amount-percentage 100
|
||||||
|
:amount-mode "%"
|
||||||
|
:account @(re-frame/subscribe [::subs/vendor-default-account value])}]]}
|
||||||
|
{:dispatch [::forms/change ::edit-transaction field value]}))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::manual-match
|
::manual-match
|
||||||
@@ -195,9 +204,8 @@
|
|||||||
:type "typeahead"
|
:type "typeahead"
|
||||||
:auto-focus true
|
:auto-focus true
|
||||||
:field [:vendor-id]
|
:field [:vendor-id]
|
||||||
:text-field [:vendor-name]
|
|
||||||
:disabled (boolean (:payment data))
|
:disabled (boolean (:payment data))
|
||||||
:event change-event
|
:event [::change-vendor]
|
||||||
:subscription data}]]]]
|
:subscription data}]]]]
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user