Bug 26524: Add Koha::Acquisition::Basket->orders
authorTomas Cohen Arazi <tomascohen@theke.io>
Wed, 23 Sep 2020 18:56:41 +0000 (15:56 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Tue, 29 Sep 2020 13:32:41 +0000 (15:32 +0200)
This patch adds a handy accessor for a basket's orders. It can be used
to embed orders on an API call or be used in controller scripts to
replace C4::* methods.

To test:
1. Apply this patches
2. Run:
   $ kshell
  k$ prove t/db_dependent/Koha/Acquisition/Basket.t
=> SUCCESS: Tests pass!
3. Sign off :-D

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Acquisition/Basket.pm
Koha/Schema/Result/Aqbasket.pm

index 1aad128..4b89fd0 100644 (file)
@@ -22,6 +22,7 @@ use Modern::Perl;
 use Koha::Database;
 use Koha::DateUtils qw( dt_from_string );
 use Koha::Acquisition::BasketGroups;
+use Koha::Acquisition::Orders;
 use Koha::Patrons;
 
 use base qw( Koha::Object Koha::Object::Mixin::AdditionalFields );
@@ -77,6 +78,22 @@ sub basket_group {
     return Koha::Acquisition::BasketGroup->_new_from_dbic( $basket_group_rs );
 }
 
+=head3 orders
+
+    my $orders = $basket->orders;
+
+Returns a Koha::Acquisition::Orders resultset, with the orders linked
+to this basket.
+
+=cut
+
+sub orders {
+    my ($self) = @_;
+
+    my $orders_rs = $self->_result->orders;
+    return Koha::Acquisition::Orders->_new_from_dbic( $orders_rs );
+}
+
 =head3 effective_create_items
 
 Returns C<create_items> for this basket, falling back to C<AcqCreateItem> if unset.
index e90d3c6..60d5633 100644 (file)
@@ -340,6 +340,13 @@ __PACKAGE__->belongs_to(
   },
 );
 
+__PACKAGE__->has_many(
+  "orders",
+  "Koha::Schema::Result::Aqorder",
+  { "foreign.basketno" => "self.basketno" },
+  { cascade_copy => 0, cascade_delete => 0 },
+);
+
 sub koha_object_class {
     'Koha::Acquisition::Basket';
 }