From 6eb69ed3ec7650b6298968c4a79e2cb4204ebb6f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 14 Jan 2014 13:33:58 +0100 Subject: [PATCH] Bug 11552: allow searching on original order number after a transfer If an order is transferred from one basket to another, it should be possible to retrieve it with the original order number (AKA order line). This patch makes it so. Test plan: - transfer an order - note the original order number and the new one - receive the order and, on the parcel page, try to find your order with the original order number and the new one. Signed-off-by: sonia bouis Signed-off-by: Brendan Gallagher Signed-off-by: Galen Charlton RM note: this works only for the most recent transfer, so if an order gets transferred multiple times, earlier order numbers won't retrieve it. --- C4/Acquisition.pm | 12 ++++++++++-- t/db_dependent/Acquisition/TransferOrder.t | 9 ++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm index 4bb3c6ee50..c2e7b3aee5 100644 --- a/C4/Acquisition.pm +++ b/C4/Acquisition.pm @@ -1747,6 +1747,14 @@ sub SearchOrders { LEFT JOIN borrowers ON aqbasket.authorisedby=borrowers.borrowernumber LEFT JOIN biblio ON aqorders.biblionumber=biblio.biblionumber LEFT JOIN biblioitems ON biblioitems.biblionumber=biblio.biblionumber + }; + + # If we search on ordernumber, we retrieve the transfered order is a transfer has been done. + $query .= q{ + LEFT JOIN aqorders_transfers ON aqorders_transfers.ordernumber_to = aqorders.ordernumber + } if $ordernumber; + + $query .= q{ WHERE (datecancellationprinted is NULL) }; @@ -1771,8 +1779,8 @@ sub SearchOrders { } if ( $ordernumber ) { - $query .= ' AND (aqorders.ordernumber=?)'; - push @args, $ordernumber; + $query .= ' AND ( aqorders.ordernumber = ? OR aqorders_transfers.ordernumber_from = ? ) '; + push @args, ( $ordernumber, $ordernumber ); } if( $search ) { $query .= ' AND (biblio.title LIKE ? OR biblio.author LIKE ? OR biblioitems.isbn LIKE ?)'; diff --git a/t/db_dependent/Acquisition/TransferOrder.t b/t/db_dependent/Acquisition/TransferOrder.t index a99f455728..de9ee4dde5 100644 --- a/t/db_dependent/Acquisition/TransferOrder.t +++ b/t/db_dependent/Acquisition/TransferOrder.t @@ -2,7 +2,7 @@ use Modern::Perl; -use Test::More tests => 8; +use Test::More tests => 11; use C4::Context; use C4::Acquisition; use C4::Biblio; @@ -78,6 +78,13 @@ is(scalar GetOrders($basketno2), 1, "1 order in basket2"); ($order) = GetOrders($basketno2); is(scalar GetItemnumbersFromOrder($order->{ordernumber}), 1, "1 item in basket2's order"); +# Bug 11552 +my $orders = SearchOrders({ ordernumber => $newordernumber }); +is ( scalar( @$orders ), 1, 'SearchOrders returns 1 order with newordernumber' ); +$orders = SearchOrders({ ordernumber => $ordernumber }); +is ( scalar( @$orders ), 1, 'SearchOrders returns 1 order with [old]ordernumber' ); +is ( $orders->[0]->{ordernumber}, $newordernumber, 'SearchOrders returns newordernumber if [old]ordernumber is given' ); + ModReceiveOrder({ biblionumber => $biblionumber, ordernumber => $newordernumber, -- 2.39.5