Bug 17457: Adv. Acquisition search with ISBN variations
authorDavid Bourgault <david.bourgault@inlibro.com>
Mon, 25 Sep 2017 20:22:51 +0000 (16:22 -0400)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 23 Mar 2018 14:45:38 +0000 (11:45 -0300)
Advanced acquisition search will now follow the "SearchWithISBNVariations" system preference.

Test plan :
0) Make sure you have orders pending or completed
1) Enable SearchWithISBNVariations if it is not enabled
2) Search for one of your orders by its ISBN, it should appear
3) Search for the same order by a variation of its ISBN, I used this website to find it : http://www.hahnlibrary.net/libraries/isbncalc.html
You should not get a result.
4) Apply patch
5) Repeat step 2-3. You should get a hit both times.
6) prove t/db_dependent/Acquisition.t

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
C4/Acquisition.pm
t/db_dependent/Acquisition.t

index 202ed7e..a257017 100644 (file)
@@ -2288,6 +2288,22 @@ sub GetHistory {
     my $total_qtyreceived = 0;
     my $total_price       = 0;
 
+    #get variation of isbn
+    my @isbn_params;
+    my @isbns;
+    if ($isbn){
+        if ( C4::Context->preference("SearchWithISBNVariations") ){
+            @isbns = C4::Koha::GetVariationsOfISBN( $isbn );
+            foreach my $isb (@isbns){
+                push @isbn_params, '?';
+            }
+        }
+        unless (@isbns){
+            push @isbns, $isbn;
+            push @isbn_params, '?';
+        }
+    }
+
     my $dbh   = C4::Context->dbh;
     my $query ="
         SELECT
@@ -2355,10 +2371,13 @@ sub GetHistory {
         push @query_params, "%$author%";
     }
 
-    if ( $isbn ) {
-        $query .= " AND biblioitems.isbn LIKE ? ";
-        push @query_params, "%$isbn%";
+    if ( @isbns ) {
+        $query .= " AND ( biblioitems.isbn LIKE " . join (" OR biblioitems.isbn LIKE ", @isbn_params ) . ")";
+        foreach my $isb (@isbns){
+            push @query_params, "%$isb%";
+        }
     }
+
     if ( $ean ) {
         $query .= " AND biblioitems.ean = ? ";
         push @query_params, "$ean";
index 0475872..891dbf0 100755 (executable)
@@ -19,9 +19,12 @@ use Modern::Perl;
 
 use POSIX qw(strftime);
 
-use Test::More tests => 65;
+use Test::More tests => 67;
+use t::lib::Mocks;
 use Koha::Database;
 
+use MARC::File::XML ( BinaryEncoding => 'utf8', RecordFormat => 'MARC21' );
+
 BEGIN {
     use_ok('C4::Acquisition');
     use_ok('C4::Biblio');
@@ -161,12 +164,32 @@ my $budgetid = C4::Budgets::AddBudget(
 );
 my $budget = C4::Budgets::GetBudget($budgetid);
 
+# Prepare a sample MARC record with a ISBN to test GetHistory()
+my $marcxml = qq{<?xml version="1.0" encoding="UTF-8"?>
+<record
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+    xsi:schemaLocation="http://www.loc.gov/MARC21/slim http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd"
+    xmlns="http://www.loc.gov/MARC21/slim">
+
+  <leader>03108cam a2200277 i 4500</leader>
+  <controlfield tag="001">a2526595</controlfield>
+  <controlfield tag="003">Koha</controlfield>
+  <controlfield tag="005">20170306104815.0</controlfield>
+  <controlfield tag="006">m     o  d        </controlfield>
+  <controlfield tag="007">cr |||||||||||</controlfield>
+  <controlfield tag="008">150723s2016    vau      b    000 0 eng d</controlfield>
+  <datafield tag="020" ind1=" " ind2=" ">
+    <subfield code="a">9780136019701</subfield>
+  </datafield>
+</record>
+};
+
 my @ordernumbers;
 my ( $biblionumber1, $biblioitemnumber1 ) = AddBiblio( MARC::Record->new, '' );
 my ( $biblionumber2, $biblioitemnumber2 ) = AddBiblio( MARC::Record->new, '' );
 my ( $biblionumber3, $biblioitemnumber3 ) = AddBiblio( MARC::Record->new, '' );
 my ( $biblionumber4, $biblioitemnumber4 ) = AddBiblio( MARC::Record->new, '' );
-my ( $biblionumber5, $biblioitemnumber5 ) = AddBiblio( MARC::Record->new, '' );
+my ( $biblionumber5, $biblioitemnumber5 ) = AddBiblio( MARC::Record->new_from_xml( $marcxml, 'utf8', 'MARC21' ), '' );
 
 # Prepare 5 orders, and make distinction beween fields to be tested with eq and with ==
 # Ex : a price of 50.1 will be stored internally as 5.100000
@@ -433,6 +456,16 @@ is( scalar( @$orders ), 1, 'GetHistory with a given ordernumber returns 1 order'
 $orders = GetHistory( ordernumber => $ordernumbers[1], search_children_too => 1 );
 is( scalar( @$orders ), 2, 'GetHistory with a given ordernumber and search_children_too set returns 2 orders' );
 
+# Test GetHistory() with and without SearchWithISBNVariations
+# The ISBN passed as a param is the ISBN-10 version of the 13-digit ISBN in the sample record declared in $marcxml
+t::lib::Mocks::mock_preference('SearchWithISBNVariations', 0);
+$orders = GetHistory( isbn => '0136019706' );
+is( scalar(@$orders), 0, "GetHistory searches correctly by ISBN" );
+
+t::lib::Mocks::mock_preference('SearchWithISBNVariations', 1);
+$orders = GetHistory( isbn => '0136019706' );
+is( scalar(@$orders), 1, "GetHistory searches correctly by ISBN" );
+
 my $budgetid2 = C4::Budgets::AddBudget(
     {
         budget_code => "budget_code_test_modrecv",