mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix for #1890
This commit is contained in:
parent
75cc024e28
commit
922c8703f5
@ -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(
|
||||
[
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user