From aa97f13411576d651b1ee95a94da1ca644a24bde Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 7 May 2018 19:29:19 -0300 Subject: [PATCH] Bug 20726: Add new method Koha::Acquisition::Order->fund MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Can be moved to a separate bug report. Sponsored-by: BULAC - http://www.bulac.fr/ Signed-off-by: Séverine QUEUNE Signed-off-by: Josef Moravec Signed-off-by: Nick Clemens --- Koha/Acquisition/Order.pm | 15 +++++++++++++++ t/db_dependent/Koha/Acquisition/Order.t | 19 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index b195ed26e9..7ec177d66f 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -20,6 +20,7 @@ use Modern::Perl; use Carp qw( croak ); use Koha::Acquisition::Baskets; +use Koha::Acquisition::Funds; use Koha::Database; use Koha::DateUtils qw( dt_from_string output_pref ); @@ -120,6 +121,20 @@ sub basket { return Koha::Acquisition::Basket->_new_from_dbic( $basket_rs ); } +=head3 fund + + my $fund = $order->fund + +Returns the fund (aqbudgets) associated to the order. + +=cut + +sub fund { + my ( $self ) = @_; + my $fund_rs = $self->_result->budget; + return Koha::Acquisition::Fund->_new_from_dbic( $fund_rs ); +} + =head2 Internal methods =head3 _type diff --git a/t/db_dependent/Koha/Acquisition/Order.t b/t/db_dependent/Koha/Acquisition/Order.t index f8382fa331..f5a20a808b 100644 --- a/t/db_dependent/Koha/Acquisition/Order.t +++ b/t/db_dependent/Koha/Acquisition/Order.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 2; +use Test::More tests => 3; use t::lib::TestBuilder; use t::lib::Mocks; @@ -97,3 +97,20 @@ subtest 'store' => sub { }; $schema->storage->txn_rollback; }; + +subtest 'fund' => sub { + plan tests => 1; + + $schema->storage->txn_begin; + my $o = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + } + ); + + my $order = Koha::Acquisition::Orders->find( $o->ordernumber ); + is( ref( $order->fund ), + 'Koha::Acquisition::Fund', + '->fund should return a Koha::Acquisition::Fund object' ); + $schema->storage->txn_rollback; +}; -- 2.39.5