@@ -, +, @@ --- Koha/Acquisition/Fund.pm | 1 + t/db_dependent/Koha/Acquisition/Fund.t | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) --- a/Koha/Acquisition/Fund.pm +++ a/Koha/Acquisition/Fund.pm @@ -42,6 +42,7 @@ associated to the fund. sub budget { my ( $self ) = @_; my $budget_rs = $self->_result->budget; + return unless $budget_rs; return Koha::Acquisition::Budget->_new_from_dbic( $budget_rs ); } --- a/t/db_dependent/Koha/Acquisition/Fund.t +++ a/t/db_dependent/Koha/Acquisition/Fund.t @@ -25,6 +25,8 @@ use t::lib::TestBuilder; use Koha::Database; +use Koha::Acquisition::Budget; + my $schema = Koha::Database->schema; my $builder = t::lib::TestBuilder->new; @@ -44,7 +46,7 @@ subtest 'to_api() tests' => sub { }; subtest 'budget' => sub { - plan tests => 1; + plan tests => 2; $schema->storage->txn_begin; my $f = $builder->build_object( @@ -57,5 +59,12 @@ subtest 'budget' => sub { is( ref( $fund->budget ), 'Koha::Acquisition::Budget', '->fund should return a Koha::Acquisition::Budget object' ); + + # Testing when budget_period_id is set as NULL + $fund->budget_period_id(undef); + $fund->update(); + is( $fund->budget, + undef, + '->fund->budget should return undef if budget_period_id is set as NULL' ); $schema->storage->txn_rollback; }; --