mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Also test attachments.
This commit is contained in:
@@ -92,7 +92,8 @@ class AccountFactory
|
||||
// create it:
|
||||
$databaseData = ['user_id' => $this->user->id,
|
||||
'account_type_id' => $type->id,
|
||||
'name' => $data['name'], 'order' => 0,
|
||||
'name' => $data['name'],
|
||||
'order' => 25000,
|
||||
'virtual_balance' => $data['virtual_balance'] ?? null, 'active' => true === $data['active'], 'iban' => $data['iban'],];
|
||||
|
||||
$currency = $this->getCurrency((int)($data['currency_id'] ?? null), (string)($data['currency_code'] ?? null));
|
||||
@@ -126,14 +127,24 @@ class AccountFactory
|
||||
// store location
|
||||
$this->storeNewLocation($return, $data);
|
||||
|
||||
// update order to be correct:
|
||||
|
||||
// set new order:
|
||||
if (array_key_exists('order', $data)) {
|
||||
$maxOrder = $this->accountRepository->maxOrder([$type->type]);
|
||||
$order = $data['order'] > $maxOrder ? $maxOrder+1 : $data['order'];
|
||||
$update = new AccountUpdateService;
|
||||
$update->setUser($return->user);
|
||||
$return = $update->updateAccountOrder($return,['order' => $order]);
|
||||
$maxOrder = $this->accountRepository->maxOrder($type->type);
|
||||
$order = null;
|
||||
if (!array_key_exists('order', $data)) {
|
||||
// take maxOrder + 1
|
||||
$order = $maxOrder + 1;
|
||||
}
|
||||
if (array_key_exists('order', $data)) {
|
||||
// limit order
|
||||
$order = (int)($data['order'] > $maxOrder ? $maxOrder + 1 : $data['order']);
|
||||
$order = 0 === $order ? $maxOrder + 1 : $order;
|
||||
}
|
||||
$updateService = app(AccountUpdateService::class);
|
||||
$updateService->setUser($return->user);
|
||||
Log::debug(sprintf('Will set order to %d', $order));
|
||||
$return = $updateService->update($return, ['order' => $order]);
|
||||
}
|
||||
|
||||
return $return;
|
||||
|
@@ -46,16 +46,16 @@ class AttachmentFactory
|
||||
public function create(array $data): ?Attachment
|
||||
{
|
||||
// append if necessary.
|
||||
$model = false === strpos($data['model'], 'FireflyIII') ? sprintf('FireflyIII\\Models\\%s', $data['model']) : $data['model'];
|
||||
$model = false === strpos($data['attachable_type'], 'FireflyIII') ? sprintf('FireflyIII\\Models\\%s', $data['attachable_type']) : $data['attachable_type'];
|
||||
|
||||
// get journal instead of transaction.
|
||||
if (Transaction::class === $model) {
|
||||
/** @var Transaction $transaction */
|
||||
$transaction = $this->user->transactions()->find((int) $data['model_id']);
|
||||
$transaction = $this->user->transactions()->find((int) $data['attachable_id']);
|
||||
if (null === $transaction) {
|
||||
throw new FireflyException('Unexpectedly could not find transaction'); // @codeCoverageIgnore
|
||||
}
|
||||
$data['model_id'] = $transaction->transaction_journal_id;
|
||||
$data['attachable_id'] = $transaction->transaction_journal_id;
|
||||
$model = TransactionJournal::class;
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ class AttachmentFactory
|
||||
$attachment = Attachment::create(
|
||||
[
|
||||
'user_id' => $this->user->id,
|
||||
'attachable_id' => $data['model_id'],
|
||||
'attachable_id' => $data['attachable_id'],
|
||||
'attachable_type' => $model,
|
||||
'md5' => '',
|
||||
'filename' => $data['filename'],
|
||||
|
Reference in New Issue
Block a user