Bug 20726: Add new method Koha::Acquisition::Order->fund
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 7 May 2018 22:29:19 +0000 (19:29 -0300)
committerNick Clemens <nick@bywatersolutions.com>
Thu, 30 Aug 2018 13:40:37 +0000 (13:40 +0000)
Can be moved to a separate bug report.

Sponsored-by: BULAC - http://www.bulac.fr/
Signed-off-by: Séverine QUEUNE <severine.queune@bulac.fr>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Koha/Acquisition/Order.pm
t/db_dependent/Koha/Acquisition/Order.t

index b195ed2..7ec177d 100644 (file)
@@ -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
index f8382fa..f5a20a8 100644 (file)
@@ -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;
+};