Fix storing of virtual balance.

This commit is contained in:
James Cole
2020-04-13 07:57:32 +02:00
parent 6daf083b3f
commit 1778f0b4f3
4 changed files with 13 additions and 14 deletions

View File

@@ -98,7 +98,7 @@ class AccountFactory
'user_id' => $this->user->id, 'user_id' => $this->user->id,
'account_type_id' => $type->id, 'account_type_id' => $type->id,
'name' => $data['name'], 'name' => $data['name'],
'virtual_balance' => $data['virtual_balance'] ?? '0', 'virtual_balance' => $data['virtual_balance'] ?? null,
'active' => true === $data['active'], 'active' => true === $data['active'],
'iban' => $data['iban'], 'iban' => $data['iban'],
]; ];
@@ -109,12 +109,12 @@ class AccountFactory
// remove virtual balance when not an asset account or a liability // remove virtual balance when not an asset account or a liability
if (!in_array($type->type, $this->canHaveVirtual, true)) { if (!in_array($type->type, $this->canHaveVirtual, true)) {
$databaseData['virtual_balance'] = '0'; $databaseData['virtual_balance'] = null;
} }
// fix virtual balance when it's empty // fix virtual balance when it's empty
if ('' === $databaseData['virtual_balance']) { if ('' === (string)$databaseData['virtual_balance']) {
$databaseData['virtual_balance'] = '0'; $databaseData['virtual_balance'] = null;
} }
$return = Account::create($databaseData); $return = Account::create($databaseData);

View File

@@ -538,15 +538,15 @@ class TransactionJournalFactory
$dataRow = $row->getArrayCopy(); $dataRow = $row->getArrayCopy();
unset($dataRow['import_hash_v2'], $dataRow['original_source']); unset($dataRow['import_hash_v2'], $dataRow['original_source']);
$json = json_encode($dataRow); $json = json_encode($dataRow, JSON_THROW_ON_ERROR, 512);
if (false === $json) { if (false === $json) {
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
$json = json_encode((string) microtime()); $json = json_encode((string) microtime(), JSON_THROW_ON_ERROR, 512);
Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow); Log::error(sprintf('Could not hash the original row! %s', json_last_error_msg()), $dataRow);
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
} }
$hash = hash('sha256', $json); $hash = hash('sha256', $json);
Log::debug(sprintf('The hash is: %s', $hash)); Log::debug(sprintf('The hash is: %s', $hash), $dataRow);
return $hash; return $hash;
} }

View File

@@ -94,12 +94,6 @@ use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
* @property-read int|null $notes_count * @property-read int|null $notes_count
* @property-read int|null $piggy_banks_count * @property-read int|null $piggy_banks_count
* @property-read int|null $transactions_count * @property-read int|null $transactions_count
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property int $account_type_id
* @property bool $encrypted
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\AccountMeta[] $accountMeta
* @property-read \Illuminate\Database\Eloquent\Collection|\FireflyIII\Models\PiggyBank[] $piggyBanks
*/ */
class Account extends Model class Account extends Model
{ {
@@ -258,7 +252,11 @@ class Account extends Model
*/ */
public function setVirtualBalanceAttribute($value): void public function setVirtualBalanceAttribute($value): void
{ {
$this->attributes['virtual_balance'] = (string) $value; $value = (string)$value;
if('' === $value) {
$value = null;
}
$this->attributes['virtual_balance'] = $value;
} }
/** /**

View File

@@ -359,6 +359,7 @@ trait JournalServiceTrait
'account_type_id' => null, 'account_type_id' => null,
'account_type' => $preferredType, 'account_type' => $preferredType,
'name' => $data['name'], 'name' => $data['name'],
'virtual_balance' => null,
'active' => true, 'active' => true,
'iban' => $data['iban'], 'iban' => $data['iban'],
] ]