From 9525caef855195b3ed5f7e00301821770b1d51b5 Mon Sep 17 00:00:00 2001 From: Koha instance kohadev-koha Date: Sat, 6 Apr 2019 16:15:20 +0000 Subject: [PATCH] Bug 14669: Add search option for managing library to orders search Currently the order search can't be limited by managing library. The patch adds the search option to the order history search form and a column for the managing library to the search results table. To test: - Create some baskets with orders - Set managing library for some, but also have some without - Apply patch - prove t/db_dependent/Acquisition.t - Go to Aquisition > Orders search tab on top > Advanced search link - Search for orders without limiting Orders with and without managing library set should show up - Limit search to a specific managing library - Verify results match expectations https://bugs.koha-community.org/show_bug.cgi?id=14667 --- C4/Acquisition.pm | 11 ++++++- acqui/histsearch.pl | 1 + .../prog/en/includes/filter-orders.inc | 8 +++++ .../prog/en/modules/acqui/histsearch.tt | 5 ++- t/db_dependent/Acquisition.t | 38 +++++++++++++++++++++- 5 files changed, 60 insertions(+), 3 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index de85953e89..968895a772 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -2276,6 +2276,7 @@ params: budget orderstatus (note that orderstatus '' will retrieve orders of any status except cancelled) + managing_library biblionumber get_canceled_order (if set to a true value, cancelled orders will be included) @@ -2296,7 +2297,8 @@ returns: 'ordernumber' => '1', 'quantity' => 1, 'quantityreceived' => undef, - 'title' => 'The Adventures of Huckleberry Finn' + 'title' => 'The Adventures of Huckleberry Finn', + 'managing_library' => 'CPL' } =cut @@ -2322,6 +2324,7 @@ sub GetHistory { my $ordernumber = $params{ordernumber}; my $search_children_too = $params{search_children_too} || 0; my $created_by = $params{created_by} || []; + my $managing_library = $params{managing_library}; my $ordernumbers = $params{ordernumbers} || []; my $additional_fields = $params{additional_fields} // []; @@ -2358,6 +2361,7 @@ sub GetHistory { aqbasket.basketgroupid, aqbasket.authorisedby, concat( borrowers.firstname,' ',borrowers.surname) AS authorisedbyname, + branch as managing_library, aqbasketgroups.name as groupname, aqbooksellers.name, aqbasket.creationdate, @@ -2484,6 +2488,11 @@ sub GetHistory { push @query_params, @$created_by; } + if ( $managing_library ) { + $query .= " AND aqbasket.branch = ? "; + push @query_params, $managing_library; + } + if ( @$ordernumbers ) { $query .= ' AND (aqorders.ordernumber IN ( ' . join (',', ('?') x @$ordernumbers ) . '))'; push @query_params, @$ordernumbers; diff --git a/acqui/histsearch.pl b/acqui/histsearch.pl index f5dca499c8..28ee536436 100755 --- a/acqui/histsearch.pl +++ b/acqui/histsearch.pl @@ -89,6 +89,7 @@ my $filters = { ordernumber => scalar $input->param('ordernumber'), search_children_too => scalar $input->param('search_children_too'), created_by => [ $input->multi_param('created_by') ], + managing_library => scalar $input->param('managing_library'), }; my $from_placed_on = eval { dt_from_string( scalar $input->param('from') ) } || dt_from_string; my $to_placed_on = eval { dt_from_string( scalar $input->param('to') ) } || dt_from_string; diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc index 42a3060c68..adcde73bc1 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/filter-orders.inc @@ -1,4 +1,5 @@ [% USE Koha %] +[% USE Branches %] [% USE KohaDates %]
  1. @@ -15,6 +16,13 @@
    +
  2. + + +
  3. diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt index c925d739e4..69e3ac6f04 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/histsearch.tt @@ -2,6 +2,7 @@ [% USE Asset %] [% USE KohaDates %] [% USE ColumnsSettings %] +[% USE Branches %] [% SET footerjs = 1 %] [% INCLUDE 'doc-head-open.inc' %] Koha › Acquisitions › [% IF ( order_loop ) %]Orders search › Search results[% ELSE %]Order search[% END %] @@ -36,7 +37,8 @@ Status Basket Basket creator - Basket group + Basket group + Managing library Invoice number Summary Vendor @@ -73,6 +75,7 @@   [% END %] + [% Branches.GetName(order.managing_library) | html %] [% IF ( order.invoicenumber ) %] [% order.invoicenumber | html %] [% ELSE %] diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index b997f70345..ff43df65fb 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -19,7 +19,7 @@ use Modern::Perl; use POSIX qw(strftime); -use Test::More tests => 75; +use Test::More tests => 76; use t::lib::Mocks; use Koha::Database; use Koha::Acquisition::Basket; @@ -795,4 +795,40 @@ subtest 'GetHistory with additional fields' => sub { is( scalar( @$history ), 1, 'GetHistory returns the order when additional field is set'); }; +subtest 'GetHistory - managing library' => sub { + plan tests => 1; + + my $orders = GetHistory(managing_library => 'CPL'); + + my $builder = t::lib::TestBuilder->new; + + my $order_basket1 = $builder->build({ source => 'Aqbasket', value => { branch => 'CPL' } }); + my $orderinfo1 ={ + basketno => $order_basket1->{basketno}, + rrp => 19.99, + replacementprice => undef, + quantity => 1, + quantityreceived => 0, + datereceived => undef, + datecancellationprinted => undef, + }; + my $order1 = $builder->build({ source => 'Aqorder', value => $orderinfo1 }); + + my $order_basket2 = $builder->build({ source => 'Aqbasket', value => { branch => 'LIB' } }); + my $orderinfo2 ={ + basketno => $order_basket2->{basketno}, + rrp => 19.99, + replacementprice => undef, + quantity => 1, + quantityreceived => 0, + datereceived => undef, + datecancellationprinted => undef, + }; + my $order2 = $builder->build({ source => 'Aqorder', value => $orderinfo2 }); + + my $history = GetHistory(managing_library => 'CPL'); + is( scalar( @$history), scalar ( @$orders ) +1, "GetHistory returns number of orders"); + +}; + $schema->storage->txn_rollback(); -- 2.11.0