From 45a7e3de789bac736abbc25d30db3f6ed4ff0924 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Wed, 3 Jun 2020 16:58:33 -0300 Subject: [PATCH] Bug 25670: Add Koha::Acquisition::Orders->filter_by_id_including_transfers This patch introduces a method to filter on the ordernumber, looking for it on the aqorders_transfers table ('ordernumber_from' field). To test: 1. Apply this patches 2. Run: $ kshell k$ prove t/db_dependent/Koha/Acquisition/Orders.t => SUCCESS: Tests pass! 3. Sign off :-D --- Koha/Acquisition/Orders.pm | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/Koha/Acquisition/Orders.pm b/Koha/Acquisition/Orders.pm index 2636b482a54..4537c658cbf 100644 --- a/Koha/Acquisition/Orders.pm +++ b/Koha/Acquisition/Orders.pm @@ -23,6 +23,7 @@ use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Acquisition::Order; +use Koha::Exceptions::Exception; use base qw(Koha::Objects); @@ -32,7 +33,7 @@ Koha::Acquisition::Orders object set class =head1 API -=head2 Class Methods +=head2 Class methods =head3 filter_by_lates @@ -130,6 +131,36 @@ sub filter_by_lates { ); } +=head3 filter_by_id_including_transfers + + my $orders = $orders->filter_by_id_including_transfers( + { + ordernumber => $ordernumber + } + ); + +When searching for orders by I, include the aqorders_transfers table +so we can find orders that have changed their ordernumber as the result of a transfer + +=cut + +sub filter_by_id_including_transfers { + my ( $self, $params ) = @_; + + Koha::Exceptions::MissingParameter->throw( "The ordernumber param is mandatory" ) + unless $params->{ordernumber}; + + return $self->search( + { + -or => [ + { 'me.ordernumber' => $params->{ordernumber} }, + { 'aqorders_transfers_ordernumber_to.ordernumber_from' => $params->{ordernumber} } + ] + }, + { join => 'aqorders_transfers_ordernumber_to' } + ); +} + =head2 Internal methods =head3 _type (internal) -- 2.26.2