Rule action will create revenue account instead of search for liability

This commit is contained in:
James Cole
2023-03-25 11:34:29 +01:00
parent 3be55adaeb
commit 976128a435
2 changed files with 12 additions and 3 deletions

View File

@@ -31,6 +31,7 @@ use FireflyIII\Models\AccountType;
use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleAction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
use FireflyIII\User; use FireflyIII\User;
use JsonException; use JsonException;
use Log; use Log;
@@ -109,10 +110,18 @@ class ConvertToDeposit implements ActionInterface
$factory = app(AccountFactory::class); $factory = app(AccountFactory::class);
$factory->setUser($user); $factory->setUser($user);
$repository = app(AccountRepositoryInterface::class);
$repository->setUser($user);
// get the action value, or use the original destination name in case the action value is empty: // get the action value, or use the original destination name in case the action value is empty:
// this becomes a new or existing revenue account. // this becomes a new or existing (revenue) account, which is the source of the new deposit.
$revenueName = '' === $this->action->action_value ? $journal['destination_account_name'] : $this->action->action_value; $revenueName = '' === $this->action->action_value ? $journal['destination_account_name'] : $this->action->action_value;
$revenue = $factory->findOrCreate($revenueName, AccountType::REVENUE); // we check all possible source account types if one exists:
$validTypes = config('firefly.expected_source_types.source.Deposit');
$revenue = $repository->findByName($revenueName, $validTypes);
if (null === $revenue) {
$revenue = $factory->findOrCreate($revenueName, AccountType::REVENUE);
}
Log::debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $this->action->action_value, $journal['destination_account_name'])); Log::debug(sprintf('ConvertToDeposit. Action value is "%s", revenue name is "%s"', $this->action->action_value, $journal['destination_account_name']));

View File

@@ -531,7 +531,7 @@ return [
'expected_source_types' => [ 'expected_source_types' => [
'source' => [ 'source' => [
TransactionTypeModel::WITHDRAWAL => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], TransactionTypeModel::WITHDRAWAL => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
TransactionTypeEnum::DEPOSIT->value => [AccountType::REVENUE, AccountType::CASH, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], TransactionTypeEnum::DEPOSIT->value => [AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE, AccountType::REVENUE, AccountType::CASH],
TransactionTypeModel::TRANSFER => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE], TransactionTypeModel::TRANSFER => [AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE],
TransactionTypeModel::OPENING_BALANCE => [ TransactionTypeModel::OPENING_BALANCE => [
AccountType::INITIAL_BALANCE, AccountType::INITIAL_BALANCE,