Skip to content

Firefly III: a personal finances manager

Fixed #3048

James Colecdebde5a2b12
diff --git a/app/TransactionRules/Actions/SetSourceAccount.php b/app/TransactionRules/Actions/SetSourceAccount.php
index d38f38edf9..5b80cad798 100644
--- a/app/TransactionRules/Actions/SetSourceAccount.php
+++ b/app/TransactionRules/Actions/SetSourceAccount.php
@@ -71,6 +71,7 @@ class SetSourceAccount implements ActionInterface
$this->repository->setUser($journal->user);
// journal type:
$type = $journal->transactionType->type;
+
// if this is a transfer or a withdrawal, the new source account must be an asset account or a default account, and it MUST exist:
if ((TransactionType::WITHDRAWAL === $type || TransactionType::TRANSFER === $type) && !$this->findAssetAccount()) {
Log::error(
@@ -110,18 +111,22 @@ class SetSourceAccount implements ActionInterface
}
/**
+ * @param string $type
+ *
* @return bool
*/
- private function findAssetAccount(): bool
+ private function findAssetAccount(string $type): bool
{
- $account = $this->repository->findByName($this->action->action_value, [AccountType::DEFAULT, AccountType::ASSET]);
+ // switch on type:
+ $allowed = config(sprintf('firefly.expected_source_types.source.%s', $type));
+ $account = $this->repository->findByName($this->action->action_value, $allowed);
if (null === $account) {
- Log::debug(sprintf('There is NO asset account called "%s".', $this->action->action_value));
+ Log::debug(sprintf('There is NO valid source account called "%s".', $this->action->action_value));
return false;
}
- Log::debug(sprintf('There exists an asset account called "%s". ID is #%d', $this->action->action_value, $account->id));
+ Log::debug(sprintf('There exists a valid source account called "%s". ID is #%d', $this->action->action_value, $account->id));
$this->newSourceAccount = $account;
return true;
@@ -132,7 +137,8 @@ class SetSourceAccount implements ActionInterface
*/
private function findRevenueAccount(): void
{
- $account = $this->repository->findByName($this->action->action_value, [AccountType::REVENUE]);
+ $allowed = config('firefly.expected_source_types.source.Deposit');
+ $account = $this->repository->findByName($this->action->action_value, $allowed);
if (null === $account) {
// create new revenue account with this name:
$data = [