Bug 12074: Filter duplicates when adding a batch from a staged file
authorLyon3 Team <koha@univ-lyon3.fr>
Tue, 24 Feb 2015 14:50:49 +0000 (15:50 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Wed, 24 Jun 2015 14:32:30 +0000 (11:32 -0300)
When adding a batch of records to a basket, duplicates are skipped and
an alert is displayed with a link to them so as they could be treated
individually.

Test plan :

You need the 2 test attached files TestFile1.mrc and TestFile2.elc
(TestFile1 includes only the title "Amilec ou La graine d'hommes" that
is also included in TestFile2)

1) go to “Stage MARC records for import” page, upload TestFile1 and
stage it (select iso 5426 encoding).
2) Manage staged record and import the batch.
3) Make sure that the new record is indexed (depending to your indexing
system and test platform).
4) Go back to go to “Stage MARC records for import” page upload
TestFile2 and stage it (select iso 5426 encoding).
5) Go to acquisitions module and create a new basket.
6) From your basket, in the “Add order to basket block”  choose  'From a
staged file'.
7) Then click File2 (‘addorder button').
8) Go down the "Import all" block and save.
9) You are redirected to the basket page : a warning is displayed to
tell you that some duplicates have been found and skipped.
There's a link on the warning throughout you can go back to the list of
remaining records and treat them individually if necesary.
10) Click the link : you fall upon the title of TestFile1 (of course as
it's a duplicate).
11) Check that the imported records have been indexed.
11) Go down the "Import all" block and save.
12) A warning is displayed saying that no records have been imported
because they all match an existing record. The “Import all” block is not
any more visible.

Signed-off-by: JA <aloi54@live.fr>

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

acqui/addorderiso2709.pl
acqui/basket.pl
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/addorderiso2709.tt
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basket.tt

index d1dd292..1c0086b 100755 (executable)
@@ -60,6 +60,7 @@ my ($template, $loggedinuser, $cookie, $userflags) = get_template_and_user({
 my $cgiparams = $input->Vars;
 my $op = $cgiparams->{'op'} || '';
 my $booksellerid  = $input->param('booksellerid');
+my $allmatch = $input->param('allmatch');
 my $bookseller = Koha::Acquisition::Bookseller->fetch({ id => $booksellerid });
 my $data;
 
@@ -123,6 +124,7 @@ if ($op eq ""){
     $template->param("batch_details" => 1,
                      "basketno"      => $cgiparams->{'basketno'},
                      loop_currencies  => \@loop_currency,
+                     "allmatch" => $allmatch,
                      );
     import_biblios_list($template, $cgiparams->{'import_batch_id'});
     if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
@@ -157,6 +159,8 @@ if ($op eq ""){
     # retrieve the file you want to import
     my $import_batch_id = $cgiparams->{'import_batch_id'};
     my $biblios = GetImportRecordsRange($import_batch_id);
+    my $duplinbatch;
+    my $imported = 0;
     my @import_record_id_selected = $input->param("import_record_id");
     my @quantities = $input->param('quantity');
     my @prices = $input->param('price');
@@ -181,6 +185,7 @@ if ($op eq ""){
 
         # 1st insert the biblio, or find it through matcher
         unless ( $biblionumber ) {
+            $duplinbatch=$import_batch_id and next if FindDuplicate($marcrecord);
             # add the biblio
             my $bibitemnum;
 
@@ -284,9 +289,14 @@ if ($op eq ""){
         } else {
             SetImportRecordStatus( $biblio->{'import_record_id'}, 'imported' );
         }
+        $imported++;
     }
     # go to basket page
-    print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=".$cgiparams->{'basketno'});
+    if ( $imported ) {
+        print $input->redirect("/cgi-bin/koha/acqui/basket.pl?basketno=".$cgiparams->{'basketno'}."&amp;duplinbatch=$duplinbatch");
+    } else {
+        print $input->redirect("/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=$import_batch_id&amp;basketno=".$cgiparams->{'basketno'}."&amp;booksellerid=$booksellerid&amp;allmatch=1");
+    }
     exit;
 }
 
index cfa803b..6805e9e 100755 (executable)
@@ -68,6 +68,7 @@ the supplier this script have to display the basket.
 my $query        = new CGI;
 our $basketno     = $query->param('basketno');
 my $booksellerid = $query->param('booksellerid');
+my $duplinbatch =  $query->param('duplinbatch');
 
 my ( $template, $loggedinuser, $cookie, $userflags ) = get_template_and_user(
     {
@@ -390,6 +391,7 @@ if ( $op eq 'delete_confirm' ) {
         grouped              => $basket->{basketgroupid},
         unclosable           => @orders ? 0 : 1, 
         has_budgets          => $has_budgets,
+        duplinbatch          => $duplinbatch,
     );
 }
 
index cf03b7c..d0414cf 100644 (file)
    <div id="bd">
        <div id="yui-main">
            <div class="yui-b">
+             [% IF ( allmatch ) %]<div class="dialog alert">
+              <h4>No records imported</h4>
+             No record have been imported because they all match an existing record in your catalog.<br />You'll have to treat them individually.
+             </div>
+             [% END %]
+
              [% IF ( batch_details ) %]
                 <h1>Add orders from [% comments %]
                     ([% file_name %] staged on [% upload_timestamp | $KohaDates with_hours => 1 %])
index 47fefeb..7e02e80 100644 (file)
             </div>
             </div>
         [% END %]
+        [% IF ( duplinbatch ) %]<div class="dialog alert">
+        <h4>Duplicate warning</h4>
+        <p>Some records have not been automatically added because they match an existing record in your catalog:<a href="/cgi-bin/koha/acqui/addorderiso2709.pl?import_batch_id=[% duplinbatch %]&amp;basketno=[% basketno %]&amp;booksellerid=[% booksellerid %]" title="Open in new window" target="_blank" class="popup" style="margin-left:10px">Display them</a></p>
+        </div>[% END %]
 
         <div id="acqui_basket_content" class="yui-g">
         [% IF ( books_loop ) %]