mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-26 13:36:15 +00:00
Update tests and code.
This commit is contained in:
@@ -332,14 +332,17 @@ trait AccountServiceTrait
|
||||
* @param string $note
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function updateNote(Account $account, string $note): bool
|
||||
{
|
||||
if ('' === $note) {
|
||||
$dbNote = $account->notes()->first();
|
||||
if (null !== $dbNote) {
|
||||
$dbNote->delete();
|
||||
try {
|
||||
$dbNote->delete();
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -365,7 +368,7 @@ trait AccountServiceTrait
|
||||
public function validIBData(array $data): bool
|
||||
{
|
||||
$data['openingBalance'] = (string)($data['openingBalance'] ?? '');
|
||||
if (isset($data['openingBalance'], $data['openingBalanceDate']) && \strlen($data['openingBalance']) > 0) {
|
||||
if ('' !== $data['openingBalance'] && isset($data['openingBalance'], $data['openingBalanceDate'])) {
|
||||
Log::debug('Array has valid opening balance data.');
|
||||
|
||||
return true;
|
||||
|
||||
@@ -96,8 +96,8 @@ trait RecurringTransactionTrait
|
||||
|
||||
/** @var TransactionCurrencyFactory $factory */
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
$currency = $factory->find($array['currency_id'], $array['currency_code']);
|
||||
$foreignCurrency = $factory->find($array['foreign_currency_id'], $array['foreign_currency_code']);
|
||||
$currency = $factory->find($array['currency_id'] ?? null, $array['currency_code'] ?? null);
|
||||
$foreignCurrency = $factory->find($array['foreign_currency_id'] ?? null, $array['foreign_currency_code'] ?? null);
|
||||
if (null === $currency) {
|
||||
$currency = app('amount')->getDefaultCurrencyByUser($recurrence->user);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Internal\Update;
|
||||
|
||||
use FireflyIII\Factory\TransactionCurrencyFactory;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Services\Internal\Support\AccountServiceTrait;
|
||||
use Log;
|
||||
|
||||
@@ -33,6 +35,7 @@ use Log;
|
||||
class AccountUpdateService
|
||||
{
|
||||
use AccountServiceTrait;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
@@ -66,6 +69,19 @@ class AccountUpdateService
|
||||
if (isset($data['currency_id']) && 0 === $data['currency_id']) {
|
||||
unset($data['currency_id']);
|
||||
}
|
||||
// find currency, or use default currency instead.
|
||||
/** @var TransactionCurrencyFactory $factory */
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
|
||||
|
||||
if (null === $currency) {
|
||||
// use default currency:
|
||||
$currency = app('amount')->getDefaultCurrencyByUser($account->user);
|
||||
}
|
||||
$currency->enabled = true;
|
||||
$currency->save();
|
||||
$data['currency_id'] = $currency->id;
|
||||
|
||||
// update all meta data:
|
||||
$this->updateMetaData($account, $data);
|
||||
|
||||
@@ -57,7 +57,7 @@ class BillUpdateService
|
||||
/** @var TransactionCurrencyFactory $factory */
|
||||
$factory = app(TransactionCurrencyFactory::class);
|
||||
/** @var TransactionCurrency $currency */
|
||||
$currency = $factory->find((int)$data['currency_id'], (string)$data['currency_code']);
|
||||
$currency = $factory->find($data['currency_id'] ?? null, $data['currency_code'] ?? null);
|
||||
|
||||
if(null === $currency) {
|
||||
// use default currency:
|
||||
|
||||
Reference in New Issue
Block a user