From 2900cee991511862501c3902c901f5f9e9289f9b Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 23 Sep 2020 15:56:41 -0300 Subject: [PATCH] Bug 26524: Add Koha::Acquisition::Basket->orders 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 Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- Koha/Acquisition/Basket.pm | 17 +++++++++++++++++ Koha/Schema/Result/Aqbasket.pm | 7 +++++++ 2 files changed, 24 insertions(+) diff --git a/Koha/Acquisition/Basket.pm b/Koha/Acquisition/Basket.pm index 1aad128a7e..4b89fd08f4 100644 --- a/Koha/Acquisition/Basket.pm +++ b/Koha/Acquisition/Basket.pm @@ -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 for this basket, falling back to C if unset. diff --git a/Koha/Schema/Result/Aqbasket.pm b/Koha/Schema/Result/Aqbasket.pm index e90d3c61e7..60d5633a58 100644 --- a/Koha/Schema/Result/Aqbasket.pm +++ b/Koha/Schema/Result/Aqbasket.pm @@ -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'; } -- 2.39.5