From 4f3b8d4f45fdce2390608f94fe116fbed6220766 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 Signed-off-by: Nick Clemens --- 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; @@ -536,3 +536,51 @@ subtest 'filter_by_late' => sub { $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.11.0