From 44c570e4330a052e4e92b7fbc04465ed3a7a9340 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 filter_by_active and 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). It also adds a method for filtering on active orders. 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 lib Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart --- Koha/Acquisition/Orders.pm | 54 +++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 3 deletions(-) diff --git a/Koha/Acquisition/Orders.pm b/Koha/Acquisition/Orders.pm index b8ee2f7d65..67b5dd0244 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,23 @@ sub filter_by_lates { ); } +=head3 filter_by_active + + my $new_rs = $orders->filter_by_active; + +Returns a new resultset filtering orders that are not active. + +=cut + +sub filter_by_active { + my ($self) = @_; + return $self->search( + { + orderstatus => [ 'new', 'ordered', 'partial' ] + } + ); +} + =head3 filter_by_current $orders->filter_by_current @@ -164,9 +182,39 @@ sub filter_by_cancelled { ); } +=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) +=head3 _type =cut @@ -174,7 +222,7 @@ sub _type { return 'Aqorder'; } -=head3 object_class (internal) +=head3 object_class =cut -- 2.39.5