Skip to content

Firefly III: a personal finances manager

Fix for #1890

James Cole922c8703f5c3
diff --git a/app/Factory/BillFactory.php b/app/Factory/BillFactory.php
index 85168bc9b0..f29e7ae04a 100644
--- a/app/Factory/BillFactory.php
+++ b/app/Factory/BillFactory.php
@@ -36,6 +36,8 @@ use Log;
*/
class BillFactory
{
+ use BillServiceTrait;
+
/**
* Constructor.
*/
@@ -46,7 +48,6 @@ class BillFactory
}
}
- use BillServiceTrait;
/** @var User */
private $user;
@@ -61,6 +62,12 @@ class BillFactory
$factory = app(TransactionCurrencyFactory::class);
/** @var TransactionCurrency $currency */
$currency = $factory->find((int)$data['currency_id'], (string)$data['currency_code']);
+
+ if(null === $currency) {
+ // use default currency:
+ $currency = app('amount')->getDefaultCurrencyByUser($this->user);
+ }
+
/** @var Bill $bill */
$bill = Bill::create(
[
diff --git a/app/Services/Internal/Update/BillUpdateService.php b/app/Services/Internal/Update/BillUpdateService.php
index 6a504e5879..cb7ebe8403 100644
--- a/app/Services/Internal/Update/BillUpdateService.php
+++ b/app/Services/Internal/Update/BillUpdateService.php
@@ -23,7 +23,9 @@ declare(strict_types=1);
namespace FireflyIII\Services\Internal\Update;
+use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Models\Bill;
+use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Services\Internal\Support\BillServiceTrait;
use Log;
/**
@@ -52,12 +54,27 @@ class BillUpdateService
*/
public function update(Bill $bill, array $data): Bill
{
+ /** @var TransactionCurrencyFactory $factory */
+ $factory = app(TransactionCurrencyFactory::class);
+ /** @var TransactionCurrency $currency */
+ $currency = $factory->find((int)$data['currency_id'], (string)$data['currency_code']);
+
+ if(null === $currency) {
+ // use default currency:
+ $currency = app('amount')->getDefaultCurrencyByUser($bill->user);
+ }
+
+ // enable the currency if it isn't.
+ $currency->enabled = true;
+ $currency->save();
+
+
$oldName = $bill->name;
$bill->name = $data['name'];
$bill->amount_min = $data['amount_min'];
$bill->amount_max = $data['amount_max'];
$bill->date = $data['date'];
- $bill->transaction_currency_id = $data['currency_id'];
+ $bill->transaction_currency_id = $currency->id;
$bill->repeat_freq = $data['repeat_freq'];
$bill->skip = $data['skip'];
$bill->automatch = true;
diff --git a/tests/Feature/Controllers/BillControllerTest.php b/tests/Feature/Controllers/BillControllerTest.php
index c4bb7799bc..b81b7b5abe 100644
--- a/tests/Feature/Controllers/BillControllerTest.php
+++ b/tests/Feature/Controllers/BillControllerTest.php
@@ -213,8 +213,8 @@ class BillControllerTest extends TestCase
//calls for transaction matcher:
// todo bad to do this:
$matcher = $this->mock(TransactionMatcher::class);
- $matcher->shouldReceive('setLimit')->once()->withArgs([100000]);
- $matcher->shouldReceive('setRange')->once()->withArgs([100000]);
+ $matcher->shouldReceive('setSearchLimit')->once()->withArgs([100000]);
+ $matcher->shouldReceive('setTriggeredLimit')->once()->withArgs([100000]);
$matcher->shouldReceive('setRule')->once()->withArgs([Mockery::any()]);
$matcher->shouldReceive('findTransactionsByRule')->once()->andReturn(new Collection);