From 0949a264b8ee5475dbeafe7e054a497bf9448be4 Mon Sep 17 00:00:00 2001 From: James Cole Date: Mon, 26 Apr 2021 06:18:30 +0200 Subject: [PATCH] Fix #4710 --- .../Actions/SetDestinationAccount.php | 12 +++++++----- app/TransactionRules/Actions/SetSourceAccount.php | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/TransactionRules/Actions/SetDestinationAccount.php b/app/TransactionRules/Actions/SetDestinationAccount.php index c530568177..fe87c4b8a1 100644 --- a/app/TransactionRules/Actions/SetDestinationAccount.php +++ b/app/TransactionRules/Actions/SetDestinationAccount.php @@ -56,8 +56,8 @@ class SetDestinationAccount implements ActionInterface */ public function actOnArray(array $journal): bool { - $user = User::find($journal['user_id']); - $type = $journal['transaction_type_type']; + $user = User::find($journal['user_id']); + $type = $journal['transaction_type_type']; /** @var TransactionJournal|null $object */ $object = $user->transactionJournals()->find((int)$journal['transaction_journal_id']); $this->repository = app(AccountRepositoryInterface::class); @@ -108,8 +108,9 @@ class SetDestinationAccount implements ActionInterface } // if this is a withdrawal, the new destination account must be a expense account and may be created: + // or it is a liability, in which case it must be returned. if (TransactionType::WITHDRAWAL === $type) { - $newAccount = $this->findExpenseAccount(); + $newAccount = $this->findWithdrawalDestinationAccount(); } Log::debug(sprintf('New destination account is #%d ("%s").', $newAccount->id, $newAccount->name)); @@ -145,9 +146,10 @@ class SetDestinationAccount implements ActionInterface /** * @return Account */ - private function findExpenseAccount(): Account + private function findWithdrawalDestinationAccount(): Account { - $account = $this->repository->findByName($this->action->action_value, [AccountType::EXPENSE]); + $allowed = config('firefly.expected_source_types.destination.Withdrawal'); + $account = $this->repository->findByName($this->action->action_value, $allowed); if (null === $account) { $data = [ 'name' => $this->action->action_value, diff --git a/app/TransactionRules/Actions/SetSourceAccount.php b/app/TransactionRules/Actions/SetSourceAccount.php index 6c1f709c1d..6a7bf3e232 100644 --- a/app/TransactionRules/Actions/SetSourceAccount.php +++ b/app/TransactionRules/Actions/SetSourceAccount.php @@ -105,8 +105,9 @@ class SetSourceAccount implements ActionInterface } // if this is a deposit, the new source account must be a revenue account and may be created: + // or its a liability if (TransactionType::DEPOSIT === $type) { - $newAccount = $this->findRevenueAccount(); + $newAccount = $this->findDepositSourceAccount(); } Log::debug(sprintf('New source account is #%d ("%s").', $newAccount->id, $newAccount->name)); @@ -140,7 +141,7 @@ class SetSourceAccount implements ActionInterface /** * @return Account */ - private function findRevenueAccount(): Account + private function findDepositSourceAccount(): Account { $allowed = config('firefly.expected_source_types.source.Deposit'); $account = $this->repository->findByName($this->action->action_value, $allowed);