From c3bab9f414819f31f37f1f12943126a7e8abd030 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 5 May 2020 15:50:17 +0200 Subject: [PATCH] Bug 23166: Add filter_by_current and _cancelled Koha::Acq::Orders methods MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Nick Clemens Signed-off-by: Joonas Kylmälä Signed-off-by: Jonathan Druart --- Koha/Acquisition/Orders.pm | 35 +++++++++++++++++ t/db_dependent/Koha/Acquisition/Order.t | 50 ++++++++++++++++++++++++- 2 files changed, 84 insertions(+), 1 deletion(-) diff --git a/Koha/Acquisition/Orders.pm b/Koha/Acquisition/Orders.pm index 2636b482a5..28b8fb80fe 100644 --- a/Koha/Acquisition/Orders.pm +++ b/Koha/Acquisition/Orders.pm @@ -130,6 +130,41 @@ sub filter_by_lates { ); } +=head3 filter_by_current + + $orders->filter_by_current + +Return the orders of the set that have not been cancelled. + +=cut + +sub filter_by_current { + my ($self) = @_; + return $self->search( + { + datecancellationprinted => [ undef, '0000-00-00' ] + } + ); +} + +=head3 filter_by_cancelled + + $orders->filter_by_cancelled + +Return the orders of the set that have been cancelled. + +=cut + +sub filter_by_cancelled { + my ($self) = @_; + return $self->search( + { + datecancellationprinted => + [ { '!=' => [ -and => ( undef, '0000-00-00' ) ] } ] + } + ); +} + =head2 Internal methods =head3 _type (internal) diff --git a/t/db_dependent/Koha/Acquisition/Order.t b/t/db_dependent/Koha/Acquisition/Order.t index 3cbdc82b0e..2fa7310ae6 100644 --- a/t/db_dependent/Koha/Acquisition/Order.t +++ b/t/db_dependent/Koha/Acquisition/Order.t @@ -19,7 +19,7 @@ use Modern::Perl; -use Test::More tests => 10; +use Test::More tests => 11; use t::lib::TestBuilder; use t::lib::Mocks; @@ -534,5 +534,53 @@ subtest 'filter_by_late' => sub { ); is( $late_orders->count, 1 ); + $schema->storage->txn_rollback; +}; + +subtest 'filter_by_current & filter_by_cancelled' => sub { + plan tests => 2; + + $schema->storage->txn_begin; + my $now = dt_from_string; + my $order_1 = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + datecancellationprinted => undef, + } + } + ); + my $order_2 = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + datecancellationprinted => undef, + } + } + ); + my $order_3 = $builder->build_object( + { + class => 'Koha::Acquisition::Orders', + value => { + datecancellationprinted => dt_from_string, + } + } + ); + + my $orders = Koha::Acquisition::Orders->search( + { + ordernumber => { + -in => [ + $order_1->ordernumber, $order_2->ordernumber, + $order_3->ordernumber, + ] + } + } + ); + + is( $orders->filter_by_current->count, 2); + is( $orders->filter_by_cancelled->count, 1); + + $schema->storage->txn_rollback; }; -- 2.39.5