Can no longer set currency of expense / revenue accounts.

This commit is contained in:
James Cole 2022-10-23 14:46:26 +02:00
parent a91f6fbfaf
commit abdb717b37
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
4 changed files with 35 additions and 2 deletions

View File

@ -288,18 +288,27 @@ class AccountFactory
$fields = $this->validCCFields;
}
// remove currency_id if necessary.
$type = $account->accountType->type;
$list = config('firefly.valid_currency_account_types');
if (!in_array($type, $list, true)) {
$pos = array_search('currency_id', $fields);
if ($pos !== false) {
unset($fields[$pos]);
}
}
/** @var AccountMetaFactory $factory */
$factory = app(AccountMetaFactory::class);
foreach ($fields as $field) {
// if the field is set but NULL, skip it.
// if the field is set but "", update it.
if (array_key_exists($field, $data) && null !== $data[$field]) {
// convert boolean value:
if (is_bool($data[$field]) && false === $data[$field]) {
$data[$field] = 0;
}
if (is_bool($data[$field]) && true === $data[$field]) {
if (true === $data[$field]) {
$data[$field] = 1;
}

View File

@ -486,6 +486,13 @@ class AccountRepository implements AccountRepositoryInterface
*/
public function getAccountCurrency(Account $account): ?TransactionCurrency
{
$type = $account->accountType->type;
$list = config('firefly.valid_currency_account_types');
// return null if not in this list.
if(!in_array($type, $list, true)) {
return null;
}
$currencyId = (int) $this->getMetaValue($account, 'currency_id');
if ($currencyId > 0) {
return TransactionCurrency::find($currencyId);

View File

@ -115,6 +115,16 @@ trait AccountServiceTrait
$fields = $this->validAssetFields;
}
// remove currency_id if necessary.
$type = $account->accountType->type;
$list = config('firefly.valid_currency_account_types');
if(!in_array($type, $list, true)) {
$pos = array_search('currency_id', $fields);
if ($pos !== false) {
unset($fields[$pos]);
}
}
// the account role may not be set in the data but we may have it already:
if (!array_key_exists('account_role', $data)) {
$data['account_role'] = null;

View File

@ -209,6 +209,13 @@ return [
'default_language' => envNonEmpty('DEFAULT_LANGUAGE', 'en_US'),
'default_locale' => envNonEmpty('DEFAULT_LOCALE', 'equal'),
// account types that may have or set a currency
'valid_currency_account_types' => [
AccountType::ASSET, AccountType::LOAN, AccountType::DEBT, AccountType::MORTGAGE,
AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::LIABILITY_CREDIT,
AccountType::RECONCILIATION
],
// "value must be in this list" values
'valid_attachment_models' => [
Account::class,